TextView 属性效果展示:
效果描述:
第一个文本框后面加了一个图片,第二个中间省略,字母全大写
第三个有超链接,第四个有阴影,第五个字母变点,第六个有勾选图片
对应的属性介绍:
TextView中的XML属性介绍:
//第一行:
android:drawableEnd="@drawable/ic_launcher” 在文本框的结尾处绘制图片。
//第二行:
android:textAllCaps=“true" 该文本框的所有字母大写。
android:ellipsize=“middle" 当文本多于文本框的长度时,从中间省略文本。
//第三行:
android:autoLink="email|phone” 该文本框会自动为改文本框内的电话和Email添加超链接。
//第四行:
android:shadowColor="#00f"
android:shadowDx="10.0"
android:shadowDy="8.0"
android:shadowRadius=“3.0"
android:shadowXXXX 为该文本框的内容添加了阴影
//第五行
android:password=“true" 该文本框会用点来代替所有文字
//第六行 (CheckedTextView)
android:checkMark="@drawable/ok”该可勾选文本框的勾选图标。
相应的代码:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="match_parent">
<!-- 设置字号为20pt,文本框结尾处绘制图片 -->
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="我爱Java"
android:textSize="20pt"
android:drawableEnd="@drawable/ic_launcher"/>
<!-- 设置中间省略,所有字母大写 -->
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:singleLine="true"
android:text="我爱Java我爱Java我爱Java我爱Java我爱Java我aaaJava"
android:ellipsize="middle"
android:textAllCaps="true"/>
<!-- 对邮件、电话增加链接 -->
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:singleLine="true"
android:text="邮件是kongyeeku@163.com,电话是02088888888"
android:autoLink="email|phone"/>
<!-- 设置文字颜色、大小,并使用阴影 -->
<TextView
android:layout_width="match_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"/>
<!-- 测试密码框 -->
<TextView android:id="@+id/passwd"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="@string/hello_world"
android:password="true"/>
<CheckedTextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="可勾选的文本"
android:checkMark="@drawable/ok" />
</LinearLayout>
参考:疯狂Android讲义