使用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 ...
随机推荐
- springmvc 格式化使用Jackjson格式化报Failed to write HTTP message
Failed to write HTTP message: org.springframework.http.converter.HttpMessageNotWritableException: Co ...
- coreseek增量索引合并
重建主索引和增量索引: [plain] view plain copy /usr/local/coreseek/bin/indexer--config /usr/local/coreseek/etc/ ...
- UNIX下的LD_PRELOAD环境变量
UNIX下的LD_PRELOAD环境变量 也许这个话题并不新鲜,因为LD_PRELOAD所产生的问题由来已久.不过,在这里,我还是想讨论一下这个环境变量.因为这个环境变量所带来的安全问题非常严重,值得 ...
- TTTAttributedLabel xib sb lineSpacing not working
https://github.com/TTTAttributedLabel/TTTAttributedLabel/issues/733 set the same text in storyboard ...
- 调用Interop.zkemkeeper.dll无法使用解决方案
调用Interop.zkemkeeper.dll无法使用 已经注册dll成功但是还是报错 检索 COM 类工厂中 CLSID 为 {00853A19-BD51-419B--2DABE57EB61F} ...
- oracle 12c 加入系统服务
1修改oratab文件 vi /etc/oratab #把后台一行的N改为Y db01:/usr/oracle/app/product/11.2.0/dbhome_1:Y 2如果安装时.bash_pr ...
- 【bzoj2073】[POI2004]PRZ
题目描述 一只队伍在爬山时碰到了雪崩,他们在逃跑时遇到了一座桥,他们要尽快的过桥. 桥已经很旧了, 所以它不能承受太重的东西. 任何时候队伍在桥上的人都不能超过一定的限制. 所以这只队伍过桥时只能分批 ...
- java从基础知识(十)java多线程(下)
首先介绍可见性.原子性.有序性.重排序这几个概念 原子性:即一个操作或多个操作要么全部执行并且执行的过程不会被任何因素打断,要么都不执行. 可见性:一个线程对共享变量值的修改,能够及时地被其它线程看到 ...
- Python爬虫利器三之Xpath语法与lxml库的用法
前面我们介绍了 BeautifulSoup 的用法,这个已经是非常强大的库了,不过还有一些比较流行的解析库,例如 lxml,使用的是 Xpath 语法,同样是效率比较高的解析方法.如果大家对 Beau ...
- nexus的使用
一.在百度网盘或官网下载nexus,并部署. 注意修改: https://repository.apache.org/content/repositories/releases/ 二.下载m ...