改变选择的Andr​​oid的ListView文本textcolors [英] Change textcolors of Android ListView text on selection

查看:181
本文介绍了改变选择的Andr​​oid的ListView文本textcolors的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想不出什么我做错了...

I can't figure out what I am doing wrong...

我有一个自定义的文件layout.xml一个ListView。在那里,我这样定义一个TextView

I have a ListView with a custom layout.xml file. In there, i define a TextView like this

<TextView android:layout_height="wrap_content" 
          android:layout_width="wrap_content"
          android:text="foo"
          android:textColor="@drawable/listitem_textcolor_selector"/>

该listitem_textcolor_selector.xml看起来是这样的:

The listitem_textcolor_selector.xml looks something like this:

<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">
    <item android:state_pressed="true" android:color="#ff0000" />
    <item android:state_selected="true" android:color="#ff0000" />
    <item android:state_focused="true" android:color="#ff0000" />
    <item android:color="#000000" />
</selector>

这类型的作品。如果我选择一行,它将正确文本更改为红色的颜色。唯一的问题是,它不会留下红色。 后一秒钟左右,该色彩就会变回黑色。

This kind of works. If I select a row, it will properly change the color of the text to red. The only problem is, that it will not stay red. After a second or so, that color will change back to black.

这里的主要问题是,行的背景将改变它的颜色和该颜色会留下,但文本的颜色不,即使为列表项目本身的选择看起来相同(期望的颜色)。

The main problem here is that the background of the row will change it's color and this color will stay, but the color of the text does not, even though the selector for the list item itself looks identical (expect the colors).

谁能告诉我,我缺少的是什么?
任何帮助AP preciated因为我对如何解决这一问题不知道:)

Can anybody tell me what I am missing? Any help is appreciated as I have no idea on how to fix this :)

感谢

编辑:
也许我还应该指出的是,我对三星Galaxy Tab 10.1平板电脑进行测试。我曾经听说过一些TouchMode的不真正了解天气,这将有事情做与我的问题...

Maybe I should also point out that I am testing on a Samsung Galaxy Tab 10.1 tablet. I once heard something about "TouchMode" without really knowing weather this will have something to do with my problem...

推荐答案

在listitem_textcolor_selector.xml添加这些状态:

In the listitem_textcolor_selector.xml add these states:

        <!-- Activated -->      
<item 
    android:state_activated="true" 
    android:color="#ff0000" />

        <!-- Active -->      
<item 
    android:state_active="true" 
    android:color="#ff0000" />  

在此之后,直到别的选择了所选项目将保持它的颜色状态。

After this, the selected item will keep it's color state until something else is selected.

希望这有助于。

这篇关于改变选择的Andr​​oid的ListView文本textcolors的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆