TextView之二:常用属性
生活随笔
收集整理的這篇文章主要介紹了
TextView之二:常用属性
小編覺得挺不錯的,現在分享給大家,幫大家做個參考.
參考自《瘋狂android講義》2.3節
//文本框結尾處繪制圖片 ? android:drawableEnd="@drawable/ic_launcher"
//不管內容多長,單行顯示 android:singleLine="true" //文字過長時,中間部分省略 android:ellipsize="middle"
//全部字母大寫 android:textAllCaps="true"
//若文字為email或者電話號碼,以特殊形式呈現 android:autoLink="email|phone"
//文字為密碼,以點代替 android:password="true"
//文字陰影相關 android:shadowColor="#0000ff" android:shadowDx="10.0" android:shadowDy="8.0" android:shadowRadius="3.0"
//指定背景圖案 android:background="@drawable/bg_border"
實例一:TextView的常用屬性
<?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"><!-- 設置字體為20pt,文本框結尾處繪制圖片 --><TextViewandroid:layout_width="fill_parent" android:layout_height="wrap_content" android:text="我愛Java"android:textSize="20pt"android:drawableEnd="@drawable/ic_launcher"/><!-- 設置中間省略, 所有字母大寫 --><TextViewandroid:layout_width="fill_parent" android:layout_height="wrap_content"android:singleLine="true" android:text="我愛Java我愛Java我愛Java我愛Java我愛Java我aaaJava"android:ellipsize="middle"android:textAllCaps="true"/><!-- 對郵件、電話增加鏈接 --><TextViewandroid:layout_width="fill_parent" android:layout_height="wrap_content"android:singleLine="true" android:text="郵件是kongyeeku@163.com,電話是02088888888"android:autoLink="email|phone"/><!-- 設置文字顏色 、大小,并使用陰影 --><TextViewandroid:layout_width="fill_parent" android:layout_height="wrap_content" android:text="測試文字"android:shadowColor="#0000ff"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="fill_parent" android:layout_height="wrap_content" android:text="@string/hello"android:password="true"/><!-- 測試CheckedTextView通過checkMark設置該文本框的勾選圖標--><CheckedTextViewandroid:layout_width="fill_parent" android:layout_height="wrap_content"android:text="可勾選的文本"android:checkMark="@drawable/ok" /> </LinearLayout>
實例二:使用xml文件指定drawable資源,并用之于TextView的背景
<?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"><!-- 通過android:background指定背景 --><TextViewandroid:layout_width="match_parent" android:layout_height="wrap_content"android:text="帶邊框的文本"android:textSize="24pt"android:background="@drawable/bg_border"/><!-- 通過android:drawableLeft繪制一張圖片 --><TextView android:layout_width="match_parent"android:layout_height="wrap_content"android:text="圓角邊框、漸變背景的文本"android:textSize="24pt"android:background="@drawable/bg_border2"/></LinearLayout>bg_border.xml <?xml version="1.0" encoding="UTF-8"?> <shape xmlns:android="http://schemas.android.com/apk/res/android"><!-- 設置背景色為透明色 --><solid android:color="#0000"/><!-- 設置紅色邊框 --><stroke android:width="4px" android:color="#f00" /> </shape>
bg_border2.xml <?xml version="1.0" encoding="UTF-8"?> <shape xmlns:android="http://schemas.android.com/apk/res/android"android:shape="rectangle"><!-- 指定圓角矩形的4個圓角的半徑 --><corners android:topLeftRadius="20px"android:topRightRadius="5px"android:bottomRightRadius="20px"android:bottomLeftRadius="5px"/><!-- 指定邊框線條的寬度和顏色 --><stroke android:width="4px" android:color="#f0f" /><!-- 指定使用漸變背景色,使用sweep類型的漸變顏色從紅色→綠色→藍色 --><gradient android:startColor="#f00"android:centerColor="#0f0"android:endColor="#00f"android:type="sweep"/> </shape>
總結
以上是生活随笔為你收集整理的TextView之二:常用属性的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: Android中的消息机制:Handle
- 下一篇: TextView之一:子类的常用属性