为什么当我移动从列表视图焦点离开背景颜色没有变化? [英] Why the background color does not change when I move focus away from a list view?

查看:231
本文介绍了为什么当我移动从列表视图焦点离开背景颜色没有变化?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个这样的布局:


--------------------------------------------------------------------------------------
| Menu                  |    Content                                                 |
|This is a ListView     |    This is a ListView                                      |
|                       |                                                            |
| Menu 1                |    Content 1                                               |
| Menu 2                |    Content 2                                               |
| Menu 3                |    Content 3                                               |
| Menu 4                |    Content 4                                               |
|                       |    Content 5                                               |
|                       |    Content 6                                               |

项目的布局文件(更新:简体

<TextView xmlns:android="http://schemas.android.com/apk/res/android"
      android:id="@android:id/text1"
      android:layout_width="match_parent"
      android:layout_height="match_parent"
      android:background="@drawable/selector_list_item"
    />

正如你可以看到我设置背景 selector_list_item ,这个选择是这样的:

更新:由于@Kelevandos提醒,我重写我的选择,并添加更多chages

<selector xmlns:android="http://schemas.android.com/apk/res/android">

    <item android:state_selected="true" android:drawable="@android:color/black" />
    <item android:state_focused="true" android:drawable="@android:color/black" />
    <item android:state_pressed="true" android:drawable="@android:color/black" />
    <item android:drawable="@android:color/white"/>

</selector>

由于我的平台是电视,所以我用的状态 state_selected = TRUE 更新:我试图添加更多的国家,但实际上只有 stated_selected 项目中使用。

Due to my platform is a TV, so I use the state state_selected=true.(updated: I tried to add more state, but in fact only stated_selected is used in project.)

因此,这里的问题后,当我在内容视图中移动,颜色将在列表视图改变,但是当我从搬走内容视图菜单认为,内容视图背景将不会更改为白色

So here is the problem, when I move in Content view, the color will change in list view, but when I move away from Content view to Menu view, the Content view background will not change to white.

顺便说一句,当我删除的android:背景=@绘制/ selector_list_item,默认的颜色变化通常

BTW, when I remove android:background="@drawable/selector_list_item", the default color change normally.

推荐答案

您的问题是,你正在使用的状态。只要修改

Your problem is the state you are using. Just change

<item android:drawable="@android:color/black" android:state_selected="true"/> 

<item 
android:state_selected="true"
android:state_focused="true"
android:drawable="@android:color/black" />  

和它应该工作打算: - )

and it should work as intended :-)

作为一个方面说明,这是继的状态值把绘部分的通用做法。

As a side note, it is a general practice to put the drawable part after the state values.

这篇关于为什么当我移动从列表视图焦点离开背景颜色没有变化?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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