TextView控件

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

 

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格式:
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类:

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"
posted @ 2014-04-27 10:27  无名十四  阅读(158)  评论(0)    收藏  举报