TextView之二:常用属性 分类: H1_ANDROID 2013-10-30 12:43 3203人阅读 评论(0) 收藏
2013-10-30 12:43
239 查看
参考自《疯狂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文件指定drawable资源,并用之于TextView的背景
bg_border.xml
bg_border2.xml
//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,文本框结尾处绘制图片 --> <TextView android:layout_width="fill_parent" android:layout_height="wrap_content" android:text="我爱Java" android:textSize="20pt" android:drawableEnd="@drawable/ic_launcher" /> <!-- 设置中间省略, 所有字母大写 --> <TextView android: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" /> <!-- 对邮件、电话增加链接 --> <TextView android:layout_width="fill_parent" android:layout_height="wrap_content" android:singleLine="true" android:text="邮件是kongyeeku@163.com,电话是02088888888" android:autoLink="email|phone" /> <!-- 设置文字颜色 、大小,并使用阴影 --> <TextView android: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设置该文本框的勾选图标 --> <CheckedTextView android: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之一:子类的常用属性 分类: H1_ANDROID 2013-10-30 15:14 770人阅读 评论(0) 收藏
- Android TextView文字过多,添加滚动条 分类: Android 2015-07-21 13:39 2人阅读 评论(0) 收藏
- ImageView一例 分类: H1_ANDROID 2013-10-30 23:02 1812人阅读 评论(0) 收藏
- 关于Android开发的editText控件怎… 分类: Android界面和组件 2014-05-30 10:59 82人阅读 评论(0) 收藏
- android imageView 图片自适应问题 分类: Android图形动画 2014-07-01 20:08 109人阅读 评论(0) 收藏
- AndroidManifest.xml中的application中的name属性 分类: android 学习笔记 2015-07-17 16:51 116人阅读 评论(0) 收藏
- 自定义view组件 分类: H1_ANDROID 2013-10-26 21:55 741人阅读 评论(0) 收藏
- AdapterView及其子类之二:使用ListActivity及ArrayAdapter创建列表 分类: H1_ANDROID 2013-11-19 22:01 1248人阅读 评论(0) 收藏
- Android常用控件-DatePicker以及对… 分类: Android开发 2014-05-30 10:56 59人阅读 评论(0) 收藏
- Android 中查看内存的使用情况集常用adb命令 标签: Androidadb 2014-06-28 10:55 57206人阅读 评论(0) 收藏 举报 分类: Android(9) 版权声
- Loader之二:CursorLoader基本实例 分类: H1_ANDROID 2013-11-16 10:50 5447人阅读 评论(0) 收藏
- 事件处理之二:点击事件监听器的五种写法 分类: H1_ANDROID 2013-09-11 10:32 4262人阅读 评论(1) 收藏
- [转]Android开发中常用工具类总结-… 分类: Android开发 2014-05-30 10:54 74人阅读 评论(0) 收藏
- 给EditText的drawableRight属性的图片设置点击事件 分类: 学习笔记 android 2015-07-06 13:20 134人阅读 评论(0) 收藏
- 关于android:scrollbarStyle属性 分类: Android开发 2014-05-30 10:57 50人阅读 评论(0) 收藏
- 菜单之二:使用xml文件定义菜单 分类: H1_ANDROID 2013-11-03 09:39 1038人阅读 评论(0) 收藏
- inflate, findViewById与setContentView的区别与联系 分类: H1_ANDROID 2014-04-18 22:54 1119人阅读 评论(0) 收藏
- adb常用命令 分类: H1_ANDROID 2013-09-08 15:22 510人阅读 评论(0) 收藏
- Intent七在属性之一:ComponentName 分类: H1_ANDROID 2013-11-10 10:54 1184人阅读 评论(1) 收藏
- Android的eclipse常用操作详解ZZ 分类: Android开发 2014-05-30 10:54 62人阅读 评论(0) 收藏