首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 移动开发 > Android >

Android TextView运用

2012-07-01 
Android TextView使用添加各种连接http://orgcent.com/android-textview-no-underline-hyperlink/添加图片

Android TextView使用

添加各种连接http://orgcent.com/android-textview-no-underline-hyperlink/

添加图片http://blog.csdn.net/knowheart/article/details/7049829

1、设置背景色,集成自View的属性,xml中设置为

android:background="#A4A4A4"

?java程序中

textView.setBackgroundColor(android.graphics.Color.RED);

注意上面setBackgroundColor参数必须为android.graphics.Color,而对于字符串的颜色值可以如下方式parseColor

textView.setBackgroundColor(android.graphics.Color.parseColor("#A4A4A4"));
?

2、textView中文字换行

同java程序

textView.setText("aa" + "\n" + "bb");

?

3、textView文字中添加链接

String content = "<a href="http://www.1688.com">alibaba</a>";textView.setText(Html.fromHtml(content));textView.setMovementMethod(LinkMovementMethod.getInstance());
?

4、textView文字样式修改http://trinea.iteye.com/blog/1143934

?

行距?android:lineSpacingExtra

四周添加图片 ?android:drawableBottom等,图片和文字距离android:drawablePadding

?

5、添加边框

见?http://trinea.iteye.com/blog/1483949

?

6、设置文字居中

更多对其属性见android:gravity

android:gravity="center"

?设置文字垂直居中并水平向右

android:gravity="center_vertical|right"

?

7、文字加粗

对于英文直接在xml中配置

android:textStyle=”bold”

?

对于中文

textView.getPaint().setFakeBoldText(true);

?

?

?

热点排行