易采站长站为您分析Android TextView字体颜色设置方法,结合实例形式总结分析了Android开发中TextView设置字体颜色的常用技巧,需要的朋友可以参考下
本文实例总结了Android TextView字体颜色设置方法。,具体如下:
对于setTextView(int a)这里的a是传进去颜色的值。例如,红色0xff0000是指0xff0000如何直接传入R.color.red是没有办法设置颜色的,只有通过文章中的第三种方法先拿到资源的颜色值再传进去。
tv.setTextColor(this.getResources().getColor(R.color.red));
关键字: android textview color
TextView的字体设置方法:
1、直接通过配置文件设置
2、在Activity类中进行设置
第一种方式很简单,用于静态或初始文字颜色的设置,方法如下:
main.xml
<?xml version="1.0" encoding="utf-8"?> <LinearLayout xmlns:android="http://www.easck.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>
color.xml
<?xml version="1.0" encoding="utf-8"?> <resources> <drawable name="white">#FFFFFF</drawable> <drawable name="dark">#000000</drawable> <drawable name="red">#FF0000</drawable> </resources> strings.xml <?xml version="1.0" encoding="utf-8"?> <resources> <string name="hello">地址:http://www.easck.com/string> <string name="app_name">丫梨的笔记本</string> </resources>










