先上Selector文件,名字为singer_fragment_top_text_style.xml,

<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item android:color="@color/colorPrimaryDark" android:state_selected="true" />
<item android:color="@color/colorAccent" android:state_selected="false" />
</selector>

有人可能会发现这个selector文件和我们平时在Drawable里面看到的不一样,因为在drawable文件夹中的selector,是不能有android:color属性的,这个文件其实是放在res/color文件夹中的;

应用的时候,只需要对TextView的textColor直接赋值就好了,如下:

<?xml version="1.0" encoding="utf-8"?>
<TextView xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/singer_choice_tv"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:layout_marginLeft="12dp"
android:layout_marginRight="12dp"
android:background="@drawable/singer_fragment_top_style"
android:gravity="center"
android:minWidth="40dp"
android:text="A"
android:textColor="@color/singer_fragment_top_text_style"

android:textSize="18sp" />

注意,对android:textColor赋值时,不是@drawable/xxxxx,而是@color/XXXXX

使用Selector改变TextView的字体颜色textColor的方法的更多相关文章

  1. listview改变选中行字体颜色

    [android]listview改变选中行字体颜色 目标:选中item,其字体设置为#3197FF,未选中的,其字体为#FFFFFF 与listvew设置选中行item背景图片一样,使用select ...

  2. Eclipse字体颜色的设置方法

    Eclipse字体颜色的设置方法.. ----------------- .---------------------此时我们就希望设置一下字体eclipse字体颜色,让他像其它编辑器一样的,有不同的 ...

  3. 使用selector修改TextView中字体的颜色

    selector想必大家都用过了,但是在修改字体的颜色的时候还是要细心. 我们在TextView中设置字体颜色一般使用 android:textColor="@color/red" ...

  4. 改变Android按钮背景颜色的高效方法

    本文将介绍一种有效改变Android按钮颜色的方法. 按钮可以在状态改变时改变其颜色(例如按下,禁用,高亮显示).但是,这需要一一说明每个状态.这篇文章将提供你一个根据状态变化轻松改变按钮颜色的方法. ...

  5. 点击LinearLayout使用selector改变TextView字体颜色

    [html] view plaincopy   <LinearLayout android:clickable="true" android:focusable=" ...

  6. textView设置按下和焦点改变时让字体颜色发生变化

    在res/color/text_color_selector.xml这个下编写: <?xml version="1.0" encoding="utf-8" ...

  7. Android界面编程--使用活动条(ActionBar)--通过ActionBar菜单改变TextView的字体和颜色

    android:orientation="vertical"(AndroidStudio不提示,这个要记住了) 昨天好不容易把ActionBar从溢出菜单overflow中弄出来了 ...

  8. 改变UITextField placeHolder 字体 颜色

    [_textSearchField setValue:[UIColor redColor] forKeyPath:@"_placeholderLabel.textColor"]; ...

  9. winform控件在Enable=false的情况下改变它的字体颜色

    [System.Runtime.InteropServices.DllImport("user32.dll ")]         public static extern int ...

随机推荐

  1. C#之设计模式

    单例的一种实现方式 1.构造函数私有化 2.声明一个静态字段,作为全局唯一的单例对象 3.声明一个静态函数,返回全局唯一的对象 using System; using System.Collectio ...

  2. supermpa配置遇到的问题

    环境 vs2010  supermap idesktop7.1.2  iobject7.1.2.net windowform 问题 在安装iobject7.1.2 64位时 在vs中的工具箱是不显示s ...

  3. <<编程之美>>1.2读后有感

    问题提出 中国象棋的"将","帅"问题,他俩不能在一条直线上.求出他们的合法位置,并且只能用一个变量. 分析 一头雾水,不明所以.往下看了下,感觉像是程序员为难 ...

  4. 后台动态添加的button,如何触发button_click事件?

    后台动态添加的button,需要在Page_Load或者Page_Init重新动态生成才能执行button_click public Panel GetContrlType() { Panel pan ...

  5. LeedCode-Two Sum

    1. Two Sum Given an array of integers, return indices of the two numbers such that they add up to a ...

  6. Lua IDE

    http://blog.csdn.net/visualcatsharp/article/details/37653107

  7. JS 工具类

    之前工作用的JavaScript比较多,总结了一下工具类,和大家分享一下,有不足之处还请多多见谅!! 1. 数组工具类(arrayUtils) var arrayUtils = {}; (functi ...

  8. Java的输入方式总结

    写java代码的时候,经常会遇到的情况就是输入输错了怎么办?大部分想的是用一个if判断,但是用if判断的话我们就无法让用户再次输入,因为if语句程序执行后就会直接退出程序.因此要想实现循环就要用whi ...

  9. Oracle 查询语句(where,order by ,like,in,distinct)

    select * from production;alter table production add productionprice number(7,2); UPDATE production s ...

  10. CSS基础总结

    CSS基础总结链接地址:http://segmentfault.com/a/1190000002773955