Android - Textview 在状态改变时改变颜色 [英] Android - Textview change color on changing of state
问题描述
如何在 TextView 的各种状态(聚焦、按下、启用)上应用颜色?
How can I apply color on the various states(focused, pressed, enabled) of the TextView?
我已经提到了这个:http://developer.android.com/reference/android/content/res/ColorStateList.html ,但不知道如何将颜色状态列表应用于 TextView?或者有其他方法吗?
I have already referred this: http://developer.android.com/reference/android/content/res/ColorStateList.html , but do not know how can I apply color state list to the TextView? or is there any other way to do so ?
我想更改背景颜色.
推荐答案
新建一个 xml
(在 drawable
文件夹中).您可以使用颜色为每个 事件状态指定图像
你可以把这个xml设置为你的背景
Create new a new xml
(in the drawable
folder). with the color you can specify image for each event state
and you can you can set this xml as you background
如果你的 xml 是 'res/drawable/abc.xml
' 然后设置背景为
if your xml is 'res/drawable/abc.xml
' then set background as
android:background="@drawable/abc"
已编辑以在状态 xml 中添加颜色
我们的xml,res/drawable/abc.xml
Edited to add color in state xml
our xml, res/drawable/abc.xml
<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item android:state_selected="true"
android:drawable="@color/gray" />
</selector>
然后在 你的 resvaluesstrings.xml
<color name="gray">#808080</color>
这篇关于Android - Textview 在状态改变时改变颜色的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!