Android软件开发之TextView详解

Android软件开发之TextView详解
<IGNORE_JS_OP> 
TextView的API 中文文档中 说明它的结构

结构
java.lang.Object
   android.view.View
        android.widget.TextView
直接子类:
    Button, CheckedTextView, Chronometer, DigitalClock, EditText
间接子类:
     AutoCompleteTextView, CheckBox, CompoundButton, ExtractEditText,MultiAutoCompleteTextView, RadioButton, ToggleButton
1.TextView中链接手机号码/网页/邮件/地图
<IGNORE_JS_OP> 
android:autoLink的可选值为(none/web/email/phone/map/all) 设置一个URL链接 ,可以点击访问。

例如:android:text="拨打手机:13888888888"
            android:autoLink="phone"

这里设置了一个链接为手机的autoLink  它会自动设别数字 过滤掉字符串"拨打手机:" 从而点击号码后会转跳到系统拨号码的界面可以拨打电话。

拨打手机号码:
<IGNORE_JS_OP>

  1. <TextView android:id="@+id/textView0"
  2. android:layout_width="fill_parent"
  3. android:layout_height="wrap_content"
  4. android:textColor="#FF0000"
  5. android:textSize="18dip"
  6. android:background="#FFFFFF"
  7. android:text="拨打手机:13888888888"
  8. android:gravity="center_vertical|center_horizontal"
  9. android:autoLink="phone"
  10. />

复制代码

访问web网页:
<IGNORE_JS_OP>

  1. <TextView android:id="@+id/textView1"
  2. android:layout_width="fill_parent"
  3. android:layout_height="wrap_content"
  4. android:textColor="#FF0000"
  5. android:textSize="18dip"
  6. android:background="#00FF00"
  7. android:text="雨松MOMO的博客:http://blog.csdn.net/xys289187120"
  8. android:gravity="center_vertical|center_horizontal"
  9. android:autoLink="web"
  10. />

复制代码

发送邮件:
<IGNORE_JS_OP> 
<IGNORE_JS_OP> 
首选须要设置自己的电子邮件 否则Android是不知道你从那里发的邮件

  1. <TextView android:id="@+id/textView2"
  2. android:layout_width="fill_parent"
  3. android:layout_height="wrap_content"
  4. android:textColor="#FF0000"
  5. android:textSize="18dip"
  6. android:background="#FFFF00"
  7. android:text="发送邮件:[email protected]"
  8. android:gravity="center_vertical|center_horizontal"
  9. android:autoLink="email"
  10. />

复制代码

谷歌地图:

设置 android:autoLink="map"后需要有google地图才可以 否则会报错

2.在TextView中显示图片

通过设置背景的方式显示
android:background="@drawable/icon"

设置图片在textView的锚点位置
android:drawableBottom="@drawable/icon"
android:drawableTop="@drawable/icon"
android:drawableLeft="@drawable/icon"
android:drawableRight="@drawable/icon"
<IGNORE_JS_OP>

  1. <TextView android:id="@+id/TextView01"
  2. android:layout_width="wrap_content"
  3. android:layout_height="wrap_content"
  4. android:text="在图片下方"
  5. android:textColor="#FF0000"
  6. android:drawableBottom="@drawable/jay"
  7. android:layout_alignParentTop="true"
  8. android:layout_centerHorizontal="true"
  9. >
  10. </TextView>
  11. <TextView android:id="@+id/TextView01"
  12. android:layout_width="wrap_content"
  13. android:layout_height="wrap_content"
  14. android:text="在图片上方"
  15. android:textColor="#FF0000"
  16. android:drawableTop="@drawable/jay"
  17. android:layout_alignParentBottom="true"
  18. android:layout_centerHorizontal="true"
  19. >
  20. </TextView>
  21. <TextView android:id="@+id/TextView01"
  22. android:layout_width="wrap_content"
  23. android:layout_height="wrap_content"
  24. android:text="在图片左边"
  25. android:textColor="#FF0000"
  26. android:drawableLeft="@drawable/jay"
  27. android:layout_alignParentLeft="true"
  28. android:layout_centerVertical="true"
  29. >
  30. </TextView>
  31. <TextView android:id="@+id/TextView01"
  32. android:layout_width="wrap_content"
  33. android:layout_height="wrap_content"
  34. android:text="在图片右边"
  35. android:textColor="#FF0000"
  36. android:drawableRight="@drawable/jay"
  37. android:layout_alignParentRight="true"
  38. android:layout_centerVertical="true"
  39. >
  40. </TextView>

复制代码

3.文本显示内容的处理

可以在textView中设置我们想要的任何效果

<IGNORE_JS_OP>

  1. <TextView android:layout_width="fill_parent"
  2. android:layout_height="wrap_content"
  3. android:textColor="#000000"
  4. android:textSize="18dip"
  5. android:background="#00FF00"
  6. android:text="文本内容"
  7. android:gravity="center_vertical|center_horizontal"
  8. />
  9. <TextView android:layout_width="fill_parent"
  10. android:layout_height="wrap_content"
  11. android:textSize="18dip"
  12. android:background="#FFFFFF"
  13. android:textColor="#FF0000"
  14. android:text="设置字符串显示为*"
  15. android:gravity="center_vertical|center_horizontal"
  16. />
  17. <TextView android:layout_width="fill_parent"
  18. android:layout_height="wrap_content"
  19. android:textSize="18dip"
  20. android:background="#FFFFFF"
  21. android:textColor="#FF0000"
  22. android:text="设置字符串显示为*"
  23. android:password="true"
  24. android:gravity="center_vertical|center_horizontal"
  25. />
  26. <TextView android:layout_width="fill_parent"
  27. android:layout_height="wrap_content"
  28. android:textSize="18dip"
  29. android:background="#FF0000"
  30. android:textColor="#FFFFFF"
  31. android:text="设置字符串阴影颜色"
  32. android:shadowColor="#000000"
  33. android:shadowRadius="3.0"
  34. android:gravity="center_vertical|center_horizontal"
  35. />
  36. <TextView android:layout_width="fill_parent"
  37. android:layout_height="wrap_content"
  38. android:textSize="18dip"
  39. android:background="#FFFFFF"
  40. android:textColor="#FF0000"
  41. android:singleLine="true"
  42. android:text="只显示一行字符串超出屏幕为‘...‘dsfusdiofjdsiofjsdiofjoisdjfiosdjfoisdjfoisdf"
  43. android:gravity="center_vertical|center_horizontal"
  44. />
  45. <TextView android:layout_width="fill_parent"
  46. android:layout_height="wrap_content"
  47. android:textSize="18dip"
  48. android:background="#FF0000"
  49. android:textColor="#FFFFFF"
  50. android:text="设置显示文字的间隔为0.5"
  51. android:textScaleX="0.5"
  52. android:gravity="center_vertical|center_horizontal"
  53. />
  54. <TextView android:layout_width="fill_parent"
  55. android:layout_height="wrap_content"
  56. android:textSize="18dip"
  57. android:background="#FF0000"
  58. android:textColor="#FFFFFF"
  59. android:text="设置显示文字的间隔为2.0"
  60. android:textScaleX="2.0"
  61. android:gravity="center_vertical|center_horizontal"
  62. />
  63. <TextView android:layout_width="fill_parent"
  64. android:layout_height="wrap_content"
  65. android:textSize="18dip"
  66. android:background="#FFFFFF"
  67. android:textColor="#FF0000"
  68. android:text="设置文字外形为 bold"
  69. android:textStyle="bold"
  70. android:gravity="center_vertical|center_horizontal"
  71. />
  72. <TextView android:layout_width="fill_parent"
  73. android:layout_height="wrap_content"
  74. android:textSize="18dip"
  75. android:background="#FFFFFF"
  76. android:textColor="#FF0000"
  77. android:text="设置文字外形为 normal"
  78. android:textStyle="normal"
  79. android:gravity="center_vertical|center_horizontal"
  80. />
  81. <TextView android:layout_width="fill_parent"
  82. android:layout_height="wrap_content"
  83. android:textSize="18dip"
  84. android:background="#FFFFFF"
  85. android:textColor="#FF0000"
  86. android:text="设置文字外形为 italic"
  87. android:textStyle="italic"
  88. android:gravity="center_vertical|center_horizontal"
  89. />
  90. <TextView android:layout_width="fill_parent"
  91. android:layout_height="wrap_content"
  92. android:background="#FFFFFF"
  93. android:textColor="#FF0000"
  94. android:text="设置文字大小   为10"
  95. android:textSize="10dip"
  96. android:gravity="center_vertical|center_horizontal"
  97. />
  98. <TextView android:layout_width="fill_parent"
  99. android:layout_height="wrap_content"
  100. android:background="#FFFFFF"
  101. android:textColor="#FF0000"
  102. android:text="设置文字大小   为15"
  103. android:textSize="15dip"
  104. android:gravity="center_vertical|center_horizontal"
  105. />
  106. <TextView android:layout_width="fill_parent"
  107. android:layout_height="wrap_content"
  108. android:background="#FFFFFF"
  109. android:textColor="#FF0000"
  110. android:text="设置文字大小   为20"
  111. android:textSize="20dip"
  112. android:gravity="center_vertical|center_horizontal"
  113. />
  114. <TextView
  115. android:layout_width="200px"
  116. android:layout_height="wrap_content"
  117. android:textSize="18dip"
  118. android:ellipsize="marquee"
  119. android:focusable="true"
  120. android:marqueeRepeatLimit="marquee_forever"
  121. android:focusableInTouchMode="true"
  122. android:scrollHorizontally="true"
  123. android:text="文字滚屏文字跑马灯效果加长加长加长加长加长加长加长加长加长加长加长加长"
  124. android:background="#FF0000"
  125. android:textColor="#FFFFFF"
  126. >
  127. </TextView>
时间: 2024-08-09 20:16:58

Android软件开发之TextView详解的相关文章

【Android】Android软件开发之ListView 详解

原创作品,允许转载,转载时请务必以超链接形式标明文章 原始出处 .作者信息和本声明.否则将追究法律责任.http://xys289187120.blog.51cto.com/3361352/657171 ListView的使用方法 ListView是Android软件开发中非常重要组件之一,基本上是个软件基本都会使用ListView ,今天我通过一个demo来教大家怎么样使用ListView组件 绘制出漂亮的列表,说道ListView就不得不说Adapter适配器,因为只有通过Adapter才可

android软件开发之TextView控件常用属性

TextView控件 text属性,设置显示的文本 textColor:设置文本颜色 textSize:设置文本字体大小 autoLink:设置文本为电话,URL连接等的时候是否显示为可点击的链接 cursorVisible:设定光标为显示或者隐藏,默认为显示 drawableTop:在文本上方输出一个drawable,如图片 drawableLeft.drawableBottom.drawableRight如上 drawablePadding:设置图片的外边距 singleLine:设置单行显

Android开发之SpannableString详解

在实际的应用开发过程中经常会遇到,在文本的不同部分显示一些不同的字体风格的信息如:文本的字体.大小.颜色.样式.以及超级链接等.一般情况下,TextView中的文本都是一个样式,对于类似的情况,可以借助SpannableString或SpannableStringBuilder对象来实现以上设置. SpannableString与SpannableStringBuilder都可以将某段文本设置成一个Span,在Android中,Span表示一段文本的效果,例如,链接形式.图像.带背景的文本等.只

Android开发之InstanceState详解

Android开发之InstanceState详解 本文介绍Android中关于Activity的两个神秘方法:onSaveInstanceState() 和 onRestoreInstanceState(),并且在介绍这两个方法之后,再分别来实现使用InstanceState保存和恢复数据功能.Android实现屏幕旋转异步下载效果这样两个示例. 首先来介绍onSaveInstanceState() 和 onRestoreInstanceState() .关于这两个方法,一些朋友可能在Andr

Android开发之WebView详解

概述: 一个显示网页的视图.这个类是你可以滚动自己的Web浏览器或在你的Activity中简单地显示一些在线内容的基础.它使用了WebKit渲染引擎来显示网页,包括向前和向后导航的方法(通过历史记录),放大和缩小,执行文本搜索等. 需要注意的是:为了让你的应用能够使用WebView访问互联网和加载网页,你必须添加Internet的权限在Android Manifest文件中: <uses-permission android:name="android.permission.INTERNE

Android开发之BroadcastReceiver详解

BroadcastReceiver,顾名思义就是"广播接收者"的意思,它是Android四大基本组件之一,这种组件本质上是一种全局的监听器,用于监听系统全局的广播消息.它可以接收来自系统和应用的的广播. 由于BroadcastReceiver是一种全局的监听器,因此它可以非常方便地实现系统不同组件之间的通信.比如Activity与通过startService()方法启动的Service之间通信,就可以借助于BroadcastReceiver来实现. BroadcastReceiver简

Android开发之InstanceState详解(转)---利用其保存Activity状态

Android开发之InstanceState详解 本文介绍Android中关于Activity的两个神秘方法:onSaveInstanceState() 和 onRestoreInstanceState(),并且在介绍这两个方法之后,再分别来实现使用InstanceState保存和恢复数据功能.Android实现屏幕旋转异步下载效果这样两个示例. 首先来介绍onSaveInstanceState() 和 onRestoreInstanceState() .关于这两个方法,一些朋友可能在Andr

android软件开发之webView.addJavascriptInterface循环渐进【一】

本篇文章由:http://www.sollyu.com/android-software-development-webview-addjavascriptinterface-cycle-of-gradual-one/ 说明 文章列表 android软件开发之webView.addJavascriptInterface循环渐进[一]: http://www.sollyu.com/?p=302 android软件开发之webView.addJavascriptInterface循环渐进[二]: h

android软件开发之webView.addJavascriptInterface循环渐进【二】

说明 文章列表 android软件开发之webView.addJavascriptInterface循环渐进[一]: http://www.sollyu.com/android-software-development-webview-addjavascriptinterface-cycle-of-gradual-oneandroid软件开发之webView.addJavascriptInterface循环渐进[二]: http://www.sollyu.com/586 上一篇文章发布之后,得到