TextView作用:在界面中显示文本。直接继承View,它还是EditText、Button两个UI组件类的父类,并且还派生了CheckedTextView。
示例:不同颜色、字体、带连接的文本
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
>
<!-- 建立一个文本框:
drawableEnd:将文本框内文字的结尾处绘制指定图像
-->
<TextView
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="我爱 Java"
android:textSize="20pt"
android:drawableEnd="@drawable/ic_launcher"
/>
<!-- 建立一个文本框:
android:singleLine:是否单行显示
android:ellipsize:在文本中间截断,并显示省略号
android:textAllCaps:是否将文本框中文字显示为大写字母
-->
<TextView
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:singleLine="true"
android:text="我爱java我爱java我爱java我爱java我爱java我爱java"
android:ellipsize="middle"
android:textAllCaps="true"
/>
<!-- 建立一个文本框:
android:autoLink:是否将指定文本转为可单击的超级链接
-->
<TextView
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:singleLine="true"
android:text="邮件是ceshi110@110.com,电话是11223344"
android:autoLink="email|phone"
/>
<!-- 建立一个文本框:
android:shadowColor:设置文本框内文字的阴影颜色
android:shadowDx:将文本框内文字的阴影在水平方向偏移
android:shadowDy:将文本框内文字的阴影在垂直方向偏移
android:shadowRadius:设置阴影的模糊程度,越大越模糊
-->
<TextView
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="测试文字"
android:shadowColor="#00f"
android:shadowDx="10.0"
android:shadowDy="8.0"
android:shadowRadius="3.0"
android:textColor="#f00"
android:textSize="18pt"
/>
<!-- 建立一个文本框:
android:password:设置该文本框为一个密码框
-->
<TextView
android:id="@+id/passwd"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="@string/hello"
android:password="true"
/>
<!-- 建立一个文本框:
android:checkMark:设置该可勾选文本框的勾选图标
-->
<CheckedTextView
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="可勾选的文本"
android:checkMark="@drawable/ok"
/>
</LinearLayout>
显示效果: