Android基本控件和Activity的基本应用

所有控件必须要有的属性:

android:layout_width(宽)
android:layout_height(高)

Android基本控件
TextView
Button
EditText
CheckBox
RadioButton
CheckTextView
TextView(显示文本信息)
控件的功能是向用户显示文本的内容,但不允许编辑

android:layout_width="wrap_content"//(设置控件宽度)
android:layout_height="50dp"//(设置控件的高度)
android:layout_gravity="center"//(设置控件相对于其所在容器的位置)
android:textSize="26sp"//(设置文本大小)
android:textColor="#ff0000"//(设置文本颜色)
android:background="#DBDBDB"//(设备控件的背景色)
android:text="登录界面"//(设置文本内容)

Button(按钮)
用户可以在该控件上单击,并能引发相应的事件处函数,Button 继承 TextView ,其子类有 CheckBox \ RadioButton \ ToggleButton 等。

android:id="@+id/btn_login"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:text="登录"
android:textSize="23sp"

EditText(用于获取用户的输入)
EdiText 是 TextView 的子类,具有TextView 的属性特点

android:id="@+id/et_password"//(设置控件id)
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:hint="请输入密码"

CheckBox()
它是 CompoutnButton 的子类,是一个带有选中/未选中状态的按钮,可用于多选的场景,也可用于只有一个选项的情况,如注册时是否同意使用协议选项。
优点:在于不用用户支填写具体的信息,只需选中选择框;
缺点:在于只有“选择”和“不选择”两种情况;
但是往往可以利用它的这个先进性来获取相应的信息。

<CheckBox
    android:id="@+id/chb_android"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:text="Android"
    android:textSize="20sp"/>

RadioButton(单选按钮)
RadioButton 同样也是 CompoundButton 的子类,它是一个单选按钮,主要用于单选的场景,需要同RadioGroup控件一起使用方可实现单选效果。
RadioGroup 是单选组合框,它用于将 RadioButton 框起来,在没有 RadioGroup的 情况下 RadioButton 可以全部选中; 而在多个 RadioButton 被 RadioButton 被 RadioGroup包含的情况下, RadioButton只可以选择一个,也就是实现了单选的效果。

<RadioButton
    android:id="@+id/rb_teenager"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:checked="true"
    android:layout_weight="1"
    android:text="男"
    android:textSize="20sp"/>

CheckTextView
CheckedTextView 类似checkbox,单选-多选。
但它支持文字,名字可以看出它继承TextView ,多了一个选择勾选框。
Activity的基本应用

  • activity 的理解
  • 直观理解就是手机屏幕上的一个界面,Activity 主要作用是将界面呈现出来,Activity 是Android 系统中的四大组件之一,可以用于显示 View 可视控件。Activity 是一个与用户交互的系统 模块,几乎所有的Activity 老师和用户进行交互的。 交互的具体作用:一是显示;二是人机互动。

  • 一个应用通常是由多个彼此松散联系的Activity组成,一般会指定应用中的某个Activity为主活动,也就是说首次启动应用时给用户呈现的Activity。将Activity设为主活动的方法。

  • `

      <category android:name="android.intent.category.LAUNCHER" />
    

`
在以上代码中,如果有多个 avtivity 想要改变启动顺序需要改变

<intent-filter>
    <action android:name="android.intent.action.MAIN" />

    <category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
```的位置



      




  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值