首页 > 其他 > 详细

TextView控件

时间:2014-04-27 15:06:38      阅读:524      评论:0      收藏:0      [点我收藏+]

1、手动创建(不建议):

 

bubuko.com,布布扣
1 TextView tv = new TextView(this);
2 
3 tv.setContent("你好");
4 
5 setContentView(tv);
View Code

 

2、建议使用单位:

宽度、高度等:dp
字体大小等:sp
3、字体颜色:
3.1、适用于整个TextView:
android:textColor
3.2、适用于部分内容:
3.2.1、HTML格式:
bubuko.com,布布扣
1 TextView tv = (TextView)findViewById(R.id.tv);
2 
3 tv.setText(HTML.fromHtml("欢迎您,<font color=red>Katherine</font>"));
View Code

3.2.2、SpannableStringBuilder类:

bubuko.com,布布扣
1 TextView tv = (TextView)findViewById(R.id.tv);
2 
3 String str = "欢迎您,Katherine";
4 
5 SpannableStringBuilder style = new SpannableStringBuilder(str);
6 
7 style.setSpan(new ForegroundColorSpan(Color.RED), 4, 13, Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
8 
9 tv.setText(style);
View Code
4、超链接:
android:autoLink
可取值:none | web | email | phone | map | all
5、跑马灯效果:
android:focusable="true"
android:ellipsize="marquee"//当文字过长时,该如何显示。可取值:start(前方显示省略号) | middle(中间显示省略号) | end(末尾显示省略号) | marquee(跑马灯形式显示)
android:marqueeRepeatLimit="marquee_forever"
android:focusableInTouchMode="true"
android:singleLine="true"

TextView控件,布布扣,bubuko.com

TextView控件

原文:http://www.cnblogs.com/hdwons/p/android_textview.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!