日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 编程资源 > 编程问答 >内容正文

编程问答

TextView之二:常用属性

發布時間:2024/1/23 编程问答 23 豆豆
生活随笔 收集整理的這篇文章主要介紹了 TextView之二:常用属性 小編覺得挺不錯的,現在分享給大家,幫大家做個參考.

參考自《瘋狂android講義》2.3節


//TextView所呈現的文字 android:text="我愛Java" //文字顏色 android:textColor="#f00" //文字尺寸 android:textSize="20pt"
//文本框結尾處繪制圖片 ? 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之二:常用属性的全部內容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。