DBMNG数据库管理与应用

抓住自己最有兴趣的东西,由浅入深,循序渐进地学……
当前位置:首页 > 移动应用 > Android

Android TextView常用属性介绍Android:drawableEnd

//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的常用属性



  1. <?xml version="1.0" encoding="utf-8"?>  
  2. <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"  
  3.     android:orientation="vertical"  
  4.     android:layout_width="fill_parent"  
  5.     android:layout_height="fill_parent"  
  6.     >  
  7.     <!-- 设置字体为20pt,文本框结尾处绘制图片  -->  
  8.     <TextView  
  9.     android:layout_width="fill_parent"   
  10.     android:layout_height="wrap_content"   
  11.     android:text="我爱Java"  
  12.     android:textSize="20pt"  
  13.     android:drawableEnd="@drawable/ic_launcher"  
  14.     />  
  15.     <!-- 设置中间省略, 所有字母大写 -->  
  16.     <TextView  
  17.     android:layout_width="fill_parent"   
  18.     android:layout_height="wrap_content"  
  19.     android:singleLine="true"   
  20.     android:text="我爱Java我爱Java我爱Java我爱Java我爱Java我aaaJava"  
  21.     android:ellipsize="middle"  
  22.     android:textAllCaps="true"  
  23.     />  
  24.     <!-- 对邮件、电话增加链接 -->  
  25.     <TextView  
  26.     android:layout_width="fill_parent"   
  27.     android:layout_height="wrap_content"  
  28.     android:singleLine="true"   
  29.     android:text="邮件是kongyeeku@163.com,电话是02088888888"  
  30.     android:autoLink="email|phone"  
  31.     />  
  32.     <!-- 设置文字颜色 、大小,并使用阴影 -->  
  33.     <TextView  
  34.     android:layout_width="fill_parent"   
  35.     android:layout_height="wrap_content"   
  36.     android:text="测试文字"  
  37.     android:shadowColor="#0000ff"  
  38.     android:shadowDx="10.0"  
  39.     android:shadowDy="8.0"  
  40.     android:shadowRadius="3.0"  
  41.     android:textColor="#f00"  
  42.     android:textSize="18pt"  
  43.     />  
  44.     <!-- 测试密码框 -->  
  45.     <TextView android:id="@+id/passwd"  
  46.     android:layout_width="fill_parent"   
  47.     android:layout_height="wrap_content"   
  48.     android:text="@string/hello"  
  49.     android:password="true"  
  50.     />  
  51.     <!-- 测试CheckedTextView  
  52.     通过checkMark设置该文本框的勾选图标  
  53.      -->  
  54.     <CheckedTextView  
  55.     android:layout_width="fill_parent"   
  56.     android:layout_height="wrap_content"  
  57.     android:text="可勾选的文本"  
  58.     android:checkMark="@drawable/ok"      
  59.         />  
  60. </LinearLayout>  



效果图如下:



实例二:使用xml文件指定drawable资源,并用之于TextView的背景



  1. <?xml version="1.0" encoding="utf-8"?>  
  2. <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"  
  3.     android:orientation="vertical"  
  4.     android:layout_width="fill_parent"  
  5.     android:layout_height="fill_parent"  
  6.     ><pre code_snippet_id="91263" snippet_file_name="blog_20131201_2_5975047" name="code" class="html"><span style="font-family:Arial,Helvetica,sans-serif"><!-- 通过android:background指定背景 --></span></pre><TextViewandroid:layout_widthTextViewandroid: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>  
  7. <pre></pre>  
  8. <br>  
  9. bg_border.xml  
  10. <p></p>  
  11. <p></p>  
  12. <pre code_snippet_id="91263" snippet_file_name="blog_20131201_3_8657242" name="code" class="html"><?xml version="1.0" encoding="UTF-8"?>  
  13. <shape xmlns:android="http://schemas.android.com/apk/res/android">  
  14.     <!-- 设置背景色为透明色 -->  
  15.     <solid android:color="#0000"/>  
  16.     <!-- 设置红色边框 -->  
  17.     <stroke android:width="4px" android:color="#f00" />  
  18. </shape></pre><br>  
  19. bg_border2.xml  
  20. <p></p>  
  21. <p></p>  
  22. <pre code_snippet_id="91263" snippet_file_name="blog_20131201_4_9595334" name="code" class="html"><?xml version="1.0" encoding="UTF-8"?>  
  23. <shape xmlns:android="http://schemas.android.com/apk/res/android"  
  24.     android:shape="rectangle">  
  25.     <!-- 指定圆角矩形的4个圆角的半径 -->  
  26.     <corners android:topLeftRadius="20px"  
  27.     android:topRightRadius="5px"  
  28.     android:bottomRightRadius="20px"  
  29.     android:bottomLeftRadius="5px"/>  
  30.     <!-- 指定边框线条的宽度和颜色 -->  
  31.     <stroke android:width="4px" android:color="#f0f" />  
  32.     <!-- 指定使用渐变背景色,使用sweep类型的渐变  
  33.     颜色从红色→绿色→蓝色 -->  
  34.     <gradient android:startColor="#f00"  
  35.         android:centerColor="#0f0"  
  36.         android:endColor="#00f"  
  37.         android:type="sweep"/>  
  38. </shape></pre><br>  
  39. <img src="http://img.blog.csdn.net/20131030142101812?watermark/2/text/aHR0cDovL2Jsb2cuY3Nkbi5uZXQvamVkaWFlbF9sdQ==/font/5a6L5L2T/fontsize/400/fill/I0JBQkFCMA==/dissolve/70/gravity/Center" alt=""><br>  
  40. <p></p>  
  41. <p><br>  
  42. </p>  
  43. <p><br>  
  44. </p>  
本站文章内容,部分来自于互联网,若侵犯了您的权益,请致邮件chuanghui423#sohu.com(请将#换为@)联系,我们会尽快核实后删除。
Copyright © 2006-2023 DBMNG.COM All Rights Reserved. Powered by DEVSOARTECH            豫ICP备11002312号-2

豫公网安备 41010502002439号