android的最常用的基本控件
序号 | 属性名称 | 作用描述 |
---|---|---|
1 | TextView | 显示文本信息 |
2 | Button | 普通按钮 |
3 | EditText | 可编辑的文本框组件(输入框) |
4 | ImageView | 用于显示图片 |
5 | CheckBox | 复选框 |
6 | RadioGroup | 单选按钮组 |
TextView控件常用的属性
序号 | 属性名称 | 作用描述 |
---|---|---|
1 | android:layout_width | 设置控件的宽度 |
2 | android:layout_height | 设置控件的高度 |
3 | android:layout_id | 设置组件的id |
4 | android:text | 设置文本内容 |
5 | android:textColor | 设置文本颜色 |
6 | android:textSize | 设置文本大小 |
7 | android:background | 设置背景颜色 |
8 | android:gravity | 设置文本相对控件的位置 |
9 | android:layout_gravity | 设置控件相对于其所在容器的位置 |
代码示例
<TextView
android:layout_width="match_parent"
android:layout_height="50dp"
android:background="#FFDEAD"
android:gravity="center"
android:text="登录界面"
android:textSize="22sp"/>
EditText控件常用属性
序号 | 属性名称 | 作用描述 |
---|---|---|
1 | android:inputType | 设置文本的类型 |
2 | android:digits | 设置允许输入哪些字符 |
3 | android:hint | 设置编辑内容为空时显示的提示信息 |
4 | android:password | 设置只能输入密码,以"."显示文本 |
5 | android:singleLine | 设置文本单行显示 |
6 | android:editable | 设置是否可编辑 |
7 | requestFocus() | 使当前组件对象获得焦点 |
8 | android:phoneNumber | 设置电话号码的输入方式 |
9 | android:ems | 设置控件的宽度为N个字符 |
ImageView控件
这里列举现在常用的一些:
序号 | 属性名称 | 作用描述 |
---|---|---|
1 | android:src | 用于设置ImageView中展示什么图片 |
2 | android:scaleType | 设置图片的填充方式 |
3 | android:tint | 将图片染成指定的颜色 |
代码示例
android:src="@mipmap/ic_launcher"
android:scaleType="fitXY" />
CheckBox控件
CheckBox的关键属性及方法如下:
(1) android:text:用于设置CheckBox控件提示文字。
(2)android:checked="true":用于设置此标签的初始状态为选中。
(3)isChecked():用于判断是否处于被选中状态。
(4)setChecked(Boolean flag):通过传递一个布尔参数来设置按钮的状态。
RadioButton控件
*****先来简单介绍一下****
Radio控件同样也是CompuondButton的子类,它是一个单选按钮,主要应用于单选的场景,需要同RadioGroup控件一起使用方可实现单选效果
RadioGroup是单选组合框,它用于将RadioButton框起来。在没有RadioGroup的情况下,RadioButton可以全部选中,而在多个RadioButton被RadioGroup包含的情况下,RadioButton只可以选择一个,也就是实现了单选的结果。
RadioButton和ChcekBox的区别如下:
~单个RadioButton在选中后,通过单击无法变为未选中的状态;
单个CheckBox在选中后,通过单击可以变为未选中的状态;
~一组RadioButton,只能同时选中一个(单选);
一组CheckBox,能同时先多个(多选);
~RadioButton在大部分UI框架中默认用圆形表示;
CheckBox在大部分UI框架下默认用矩形表示;
Activity的简介
******看这里的.xml,它的对应的控件就是Activity,那么这里的.xml是它所对应的布局,上面的AndroidManifest.xml是它的控制器,你想让它运行那个,就可以通过剪切,粘贴的步骤,让它运行,看一下它里面的内容
<application
android:allowBackup="true"
android:icon="@mipmap/ic_launcher"
android:label="@string/app_name"
android:roundIcon="@mipmap/ic_launcher_round"
android:supportsRtl="true"
android:theme="@style/AppTheme">
<activity android:name=".exit"></activity>
<activity android:name=".KeyActivity">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity android:name=".BMIActivity">
~好! 这次我们先讲那么多,下次再会。