android TextView的字体颜色设置的多种方法
2014-08-06 16:47
751 查看
android TextView的字体颜色设置的多种方法
分类: Android学习 2012-05-04 10:30
14658人阅读 评论(1)
收藏
举报
androidencodinglayoutstringxml
转自:http://yahaitt.iteye.com/blog/454439
TextView的字体设置方法:
1、直接通过配置文件设置
2、在Activity类中进行设置
先看效果图:
![](https://oscdn.geek-share.com/Uploads/Images/Content/201406/e76cd6c64fbdb30bea36d81c14fc6410.jpg)
项目结构图:
![](https://oscdn.geek-share.com/Uploads/Images/Content/201406/dece0654eaf03ad53e4c2f23648dd96b.jpg)
第一种方式很简单,用于静态或初始文字颜色的设置,方法如下:
main.xml
[html]
view plaincopyprint?
<SPAN
style="FONT-FAMILY: FangSong_GB2312; FONT-SIZE: 16px"><STRONG><?xml
version="1.0"
encoding="utf-8"?>
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:background="@drawable/white"
>
<TextView
android:id="@+id/tv01"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="@string/hello"
android:autoLink="all"
android:textColor="@color/red"
/>
</LinearLayout></STRONG></SPAN>
<span style="FONT-FAMILY: FangSong_GB2312; FONT-SIZE: 16px"><strong><?xml version="1.0" encoding="utf-8"?> <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:orientation="vertical" android:layout_width="fill_parent" android:layout_height="fill_parent" android:background="@drawable/white" > <TextView android:id="@+id/tv01" android:layout_width="fill_parent" android:layout_height="wrap_content" android:text="@string/hello" android:autoLink="all" android:textColor="@color/red" /> </LinearLayout></strong></span>
color.xml
[html]
view plaincopyprint?
<SPAN
style="FONT-FAMILY: FangSong_GB2312; FONT-SIZE: 16px"><STRONG><?xml
version="1.0"
encoding="utf-8"?>
<resources>
<color
name="red">#FF0000</color>
</resources></STRONG></SPAN>
<span style="FONT-FAMILY: FangSong_GB2312; FONT-SIZE: 16px"><strong><?xml version="1.0" encoding="utf-8"?> <resources> <color name="red">#FF0000</color> </resources></strong></span>
strings.xml
[html]
view plaincopyprint?
<SPAN
style="FONT-FAMILY: FangSong_GB2312; FONT-SIZE: 16px"><STRONG><?xml
version="1.0"
encoding="utf-8"?>
<resources>
<string
name="hello">地址:http://yahaitt.iteye.com</string>
<string
name="app_name">丫梨的笔记本</string>
</resources></STRONG></SPAN>
<span style="FONT-FAMILY: FangSong_GB2312; FONT-SIZE: 16px"><strong><?xml version="1.0" encoding="utf-8"?> <resources> <string name="hello">地址:http://yahaitt.iteye.com</string> <string name="app_name">丫梨的笔记本</string> </resources></strong></span>
上面将资源部分分成了3个部分,目的是为了清晰,当然你也可以只建一个xml文件放在res目录下,而且文件名称可以随便命名。
注意两个地方:
1、main.xml的TextView标签中:
android:textColor="@color/red"
2、color.xml中:
<color name="red">#FF0000</color>
@color指获取资源文件中(所有res目录下的xml文件)的<color>标签
/red指在标签下找其name值为red的内容,此时其值为#FF0000
因此,这里我们还可以这样做:
android:textColor="@drawable/red"
@drawable指获取资源文件中<drawable>标签
/red指在标签下找其name值为red的内容
以此类推,相信你也就知道了如果是在strings.xml中该怎么做了。
相关文章推荐
- Android设置TextView字体呈现多种颜色的方法
- android TextView的字体颜色设置的多种方法
- 【Android基础】TextView的字体颜色设置的多种方法
- android TextView的字体颜色设置的多种方法(转)
- android TextView的字体颜色设置的多种方法
- android TextView的字体颜色设置的多种方法(续)
- android TextView的字体颜色设置的多种方法
- TextView的字体颜色设置的多种方法
- Android 一个TextView中设置文字不同字体大小和颜色的最完整方法
- TextView的字体颜色设置的多种方法
- Android一个TextView设置多种颜色的2种高效方法
- Android一个TextView设置多种颜色的2种高效方法
- Android TextView字体颜色设置方法小结
- android在TextView中设置超链接,字体大小,字体颜色,图片
- android TextView、EditText对部分内容设置颜色、字体、超链接、图片
- android中用Spannable在TextView中设置超链接、颜色、字体
- Android中TextView中文字体粗体的设置方法
- android中用Spannable在TextView中设置超链接、颜色、字体
- 【工作笔记】android TextView、EditText对部分内容设置颜色、字体、超链接、图片
- android中用Spannable在TextView中设置超链接、颜色、字体