本章将介绍一下内容,均为XML设置UI:
- 文本框
- 编辑框
- 普通按钮&图片按钮
- 单选按钮
- 复选框
文本框TextView
支持的XML属性
属性 | 作用 | 值 |
---|---|---|
android:autoLinkl | 将文本以指定的格式转变 | none、web、email、phone、map、all |
android:gravity | 设置文本框内的的文本对齐方式,多个属性值用竖线隔开 | top、bottom、left、right、center_vertical、fill_vertical、center_horizon、fill_horizon、center、fill、clip_vertical、clip_horizon |
android:hint | 当文本框无值时设置默认显示文本 | |
android:inputType | 指定文本框显示文本的内容 | textPassword、textEmailAddress、phone、data |
android:singleLine | 文本是否单行显示 | true、false |
android:text | 显示文本 | |
android:textColor | 文本显示颜色 | #rgb、#argb、#rrggbb、#aarrggbb |
android:textSize | 文本大小 | dp、px、pt、sp、in |
android:width | 文本框的宽 | dp、px、pt、sp、in |
android:height | 文本框的长度 | dp、px、pt、sp、in |
android:drawableTop | 文本框中图片在文本的上边 | @drawable/XXX |
android:drawableBottom | 文本框中图片在文本的下边 | @drawable/XXX |
android:drawableLeft | 文本框中图片在文本的左边 | @drawable/XXX |
android:drawableRight | 文本框中图片在文本的右边 | @drawable/XXX |
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
android:paddingBottom="@dimen/activity_vertical_margin"
android:paddingLeft="@dimen/activity_horizontal_margin"
android:paddingRight="@dimen/activity_horizontal_margin"
android:paddingTop="@dimen/activity_vertical_margin"
tools:context=".MainActivity" >
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="123456789"
android:autoLink="phone"
/>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="123456789@qq.com"
android:autoLink="email"
/>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="www.baidu.com"
android:autoLink="web"
/>
<!--autoLink中的格式要与text中的内容相照应-->
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="www.baidu.com"
android:autoLink="phone"
/>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="显示文本信息"
/>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:hint="无内容时显示的信息"
/>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:singleLine="true"
android:text="单行显示1234567890111111111111111111111111111"
/>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="无单行显示属性1234567890111111111111111111111111111"
/>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="颜色"
android:textColor="#0ff"
/>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="大小"
android:textSize="55sp"
/>
<!--字体大小不会变,但标签所占的面积发生了变化-->
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="宽"
android:width="88dp"
/>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="高"
android:height="105dp"
/>
<TextView
android:layout_width="100dp"
android:layout_height="50dp"
android:text="权重右"
android:gravity="right"
/>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="带图片且图片在上"
android:drawableTop="@drawable/ic_launcher"
/>
<!--密码类型-->
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="123456789"
android:inputType="textPassword"
/>