以下所有控件都只显示本控件代码,运行效果图会在原基础上添加。

一.TextView(文本框):

TextView用来向用户显示文本,这是最基本的视图。

 <TextView        android:id="@+id/textView1"        android:layout_width="wrap_content"        android:layout_height="wrap_content"        android:background="#e0ffff"        android:text="TextView"        android:textColor="#d2691e"        android:layout_gravity="center"        android:textSize="30sp"         />  


运行效果:



android:background 设置背景颜色

android:text 设置显示内容

android:textColor 设置字体颜色

android:layout_gravity 设置本控件居中显示

android:textSize 设置字体大小


二.EditText(编辑框):

EditText允许让用户编辑其文本内容。

<EditText        android:id="@+id/editText1"        android:layout_width="match_parent"        android:layout_height="wrap_content"        android:hint="请输入用户名"        android:background="#ffe4c4"        />


运行效果:

常用属性:

android:numeric 设置编辑框可输入文本类型。

android:singleLine 设置单行输入,设置为true,则文字不会自动换行。

android:password 为true时,只能输入密码。

android:textScaleX 设置字与字之间的间距。

android:minLines 设置文本最小行数。

android:ems 设置编辑框多少文字长度。

三.Button(按钮):

Button表示按钮控件。

<Button        android:id="@+id/button1"        android:layout_width="wrap_content"        android:layout_height="wrap_content"        android:text="按钮" />

运行效果:


常用属性:

android:onClick 设置事件方法名称。

android:clickable 设置此按钮是否允许点击。true为允许点击。false为不允许点击。


四.RadioGroup、RadioButton(单项选择):

我们RadioGroupRadioButton组合起来完成单项选择的功能。

<RadioGroup         android:id="@+id/RadioGroup"        android:layout_width="wrap_content"        android:layout_height="wrap_content"        android:orientation="vertical"        >        <RadioButton            android:id="@+id/radioButton3"            android:layout_width="wrap_content"            android:layout_height="wrap_content"            android:text="太阳" />        <RadioButton            android:id="@+id/radioButton2"            android:layout_width="wrap_content"            android:layout_height="wrap_content"            android:text="月亮" />        <RadioButton            android:id="@+id/radioButton1"            android:layout_width="wrap_content"            android:layout_height="wrap_content"            android:text="星星" />      </RadioGroup>

运行效果:

单项选择只能在多个选择中选择其中一个。

.CheckBox(多项选择)

    <CheckBox        android:id="@+id/checkBox1"        android:layout_width="wrap_content"        android:layout_height="wrap_content"        android:text="天" />    <CheckBox        android:id="@+id/checkBox2"        android:layout_width="wrap_content"        android:layout_height="wrap_content"        android:text="地" />    <CheckBox        android:id="@+id/checkBox3"        android:layout_width="wrap_content"        android:layout_height="wrap_content"        android:text="海" />

运行效果:

多项选择与单项选择的区别就是多项选择可以选择多个选项,而单项选择只能多选一。





更多相关文章

  1. Android开发前奏
  2. Android用户界面 UI组件--自动提示输入框 AutoCompleteTextView
  3. Android(安卓)Dialog的使用
  4. Android(安卓)常用样式设置
  5. listview常用的优化技巧
  6. android语音搜索结果显示页实现
  7. Android深入探究-- 实现即时拍照并上传
  8. Android(安卓)强制设置横屏或竖屏 设置全屏
  9. android shape的使用

随机推荐

  1. Esys Demo
  2. CSS伪类选择器和CSS盒模型常用属性
  3. 伪类选择器的应用/盒模型的分析
  4. 【Linux学习】OpenCV+ROS 实现人脸识别(Ub
  5. 常用的两种伪类选择器
  6. 伪类和伪元素和盒模型
  7. Ubuntu软件更新更换源
  8. CSS常用伪类选择器的总结与盒子模型的简
  9. 0707伪类选择器/盒模型
  10. html基础:css伪类选择器的使用和盒模型的