如何拥有安卓系统:背景颜色,并且仍然保留安卓系统中列表的灰色焦点突出显示



我正在将我的应用程序移植到Chrome操作系统,应用程序中有一些地方可以使用箭头键导航,但当前关注的元素没有以任何方式突出显示。我发现每当我为这样的元素设置背景颜色时

<LinearLayout 
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
...
android:background="@color/white" >
...
</LinearLayout>

则聚焦元素的默认高亮显示将不显示。删除它将显示默认背景(并不总是和我想要的一样(。

此外,在ListView中使用选择器的情况下,背景位于要高亮显示的可绘制对象的前面(如果颜色有些透明,则可以看到(。

<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android"
android:exitFadeDuration="@android:integer/config_mediumAnimTime" >
<item android:state_pressed="false" android:state_focused="true" android:drawable="@drawable/list_focused" />
<item android:state_pressed="true" android:drawable="@drawable/list_pressed" />
<item android:drawable="@color/white" />
</selector>

这更奇怪,因为我有一种(可能是不正确的(印象,即选择器只会选择其中一个项目。

我不能发布太多代码,因为这是工作代码,但无论哪里有列表,这都会在整个应用程序中发生。

如果为ListView中的视图定义了selector,请根据文档将ListView上的drawSelectorOnTop属性设置为true。

最新更新