textview的使用(别人的例子,我用来 参考的)

今天主要给大家分享一下Android下各种TextView的使用方法。主要从TextView中链接手机号码/网页/邮件/地图、TextView中显示图片、TextView文本显示内容的处理这3方面来讲解,原文来自CSDN博客。

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中链接手机号码/网页/邮件/地图

android:autoLink的可选值为(none/web/email/phone/map/all) 设置一个URL链接 ,可以点击访问。
例如:android:text="拨打手机:13888888888"
            android:autoLink="phone"
这里设置了一个链接为手机的autoLink  它会自动设别数字 过滤掉字符串"拨打手机:" 从而点击号码后会转跳到系统拨号码的界面可以拨打电话。
拨打手机号码:

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

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

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

     

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

设置 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"

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

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

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

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值