使用Selector改变TextView的字体颜色textColor的方法
先上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的方法的更多相关文章
- listview改变选中行字体颜色
[android]listview改变选中行字体颜色 目标:选中item,其字体设置为#3197FF,未选中的,其字体为#FFFFFF 与listvew设置选中行item背景图片一样,使用select ...
- Eclipse字体颜色的设置方法
Eclipse字体颜色的设置方法.. ----------------- .---------------------此时我们就希望设置一下字体eclipse字体颜色,让他像其它编辑器一样的,有不同的 ...
- 使用selector修改TextView中字体的颜色
selector想必大家都用过了,但是在修改字体的颜色的时候还是要细心. 我们在TextView中设置字体颜色一般使用 android:textColor="@color/red" ...
- 改变Android按钮背景颜色的高效方法
本文将介绍一种有效改变Android按钮颜色的方法. 按钮可以在状态改变时改变其颜色(例如按下,禁用,高亮显示).但是,这需要一一说明每个状态.这篇文章将提供你一个根据状态变化轻松改变按钮颜色的方法. ...
- 点击LinearLayout使用selector改变TextView字体颜色
[html] view plaincopy <LinearLayout android:clickable="true" android:focusable=" ...
- textView设置按下和焦点改变时让字体颜色发生变化
在res/color/text_color_selector.xml这个下编写: <?xml version="1.0" encoding="utf-8" ...
- Android界面编程--使用活动条(ActionBar)--通过ActionBar菜单改变TextView的字体和颜色
android:orientation="vertical"(AndroidStudio不提示,这个要记住了) 昨天好不容易把ActionBar从溢出菜单overflow中弄出来了 ...
- 改变UITextField placeHolder 字体 颜色
[_textSearchField setValue:[UIColor redColor] forKeyPath:@"_placeholderLabel.textColor"]; ...
- winform控件在Enable=false的情况下改变它的字体颜色
[System.Runtime.InteropServices.DllImport("user32.dll ")] public static extern int ...
随机推荐
- kailli linux download
https://www.offensive-security.com/kali-linux-arm-images/ Courses Certifications Online Labs Penetra ...
- HTTP 基础知识
HTTP是一种协议.HTTP使用流程,一般情况下, 第一:由HTTP客户端发出请求,创建端口. 第二:HTTP服务器在端口监听客户端的请求. 第三:一旦收到请求,HTTP服务器向客户端返回状态和内容. ...
- python3 安装scrapy
twisted(网络异步框架) wget https://pypi.python.org/packages/dc/c0/a0114a6d7fa211c0904b0de931e8cafb5210ad82 ...
- 海拔高度图*.dem文件的读取—vtkDEMReader
vtkDEMReader reads digital elevation files and creates image data. Digital elevation files are produ ...
- [Storm] Storm与asm的恩恩怨怨
asm的引用冲突 1. Jersey & Storm 0.9.3 jersey 1.8 (which depends on asm 3.0) Storm 0.93 (which depends ...
- iOS动态部署之RSA加密传输Patch补丁
概要:这一篇博客主要说明下iOS客户端动态部署方案中,patch(补丁)是如何比较安全的加载到客户端中. 在整个过程中,需要使用RSA来加密(你可以选择其它的非对称加密算法),MD5来做校验(同样,你 ...
- linux vi(vim)常用命令汇总
1 查找 /xxx(?xxx) 表示在整篇文档中搜索匹配xxx的字符串, / 表示向下查找, ? 表示向上查找其中xxx可以是正规表达式,关于正规式就不多说了. 一般来说是区分大小写的, 要想不区分大 ...
- 如何让两个div在同一行显示?一个float搞定
最近在学习div和css,遇到了一些问题也解决了很多以前以为很难搞定的问题.比如:如何让两个div显示在同一行呢?(不是用table表格,table对SE不太友好)其实,<div> 是一个 ...
- pic
- hdu 4329
problem:http://acm.hdu.edu.cn/showproblem.php?pid=4329 题意:模拟 a. p(r)= R'/i rel(r)=(1||0) R ...