如何做好Android中的TextView中选择的项目永久文本颜色的变化? [英] How to do permanent text color change in TextView selected item in Android?
问题描述
我要做出关键preSS永久性的颜色改变上一个TextView。
I want to make permanent color change on key press on a TextView.
下面是我的颜色选择驻留在RES /彩色文件夹中。
Here is my color selector resides in res/color folder.
<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item android:state_selected="true" android:color="#a7524a"/>
<item android:state_focused="true" android:state_enabled="false" android:color="#a7524a"/>
<item android:state_pressed="true" android:color="#a7524a"/>
<item android:color="#595959"/>
</selector>
在TextView中我提到它作为
In TextView I refer it as
android:textColor="@color/bright_text_dark_focused"
它工作正常。我想使颜色永久不变的,当用户presses一个TextView项目和释放。默认情况下它去上发布的默认颜色。
It works fine. I want to make the color change permanent when user a presses a TextView item and releases. By default it goes to the default color on release.
更新:
我已经改变了颜色选择为
I have changed the color selector as
<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item android:state_focused="true" android:color="#a7524a"/>
<item android:state_pressed="true" android:color="#a7524a" />
<item android:color="#595959"/>
</selector>
这是之前的工作相同。我已经加入
This is working as same before. I have added
android:textIsSelectable = "true"
在TextView的财产。然后在选择物业的背景颜色消失。但是,当我点击项目的文本颜色变成永久性的。任何线索为什么出现这种情况?其实我有一个ListView这里面的TextView。背景颜色属性是从ListView控件。
property in the TextView . Then the background color on selection property disappears. But the text color becomes permanent when I click on the items. Any clue for why this happens? Actually I have this textview inside a listview. The background color property is from ListView.
推荐答案
安卓state_activated必须解决您的问题:
android:state_activated must solve your problem:
<item android:state_activated="true" android:color="#fff"/>
您可以设定奥斯陆本作的ListView的:
You may olso set this for your listView:
mListView.setChoiceMode(ListView.CHOICE_MODE_SINGLE);
当ListView项单击此:
and when listView item clicked this:
mListView.setItemChecked(position, true);
这篇关于如何做好Android中的TextView中选择的项目永久文本颜色的变化?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!