0

我创建了一个自定义列表视图,但是当我按下一个项目时,我没有将默认的按下样式应用于特定的行项目。

按下前的样式(默认)
在此处输入图像描述

按下后的样式(按下):
在此处输入图像描述

我的自定义列表视图的代码:

ListView list = (ListView) findViewById(android.R.id.list);
String items[] = {"cat", "dog", "horse"};

list.setAdapter(new myAdapter(items));

现在我怎样才能删除这些橙色区域?

4

2 回答 2

0

只需创建一个具有透明颜色的可绘制对象,如下所示:

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

<item android:state_window_focused="false" android:drawable="@android:color/transparent"/>

<!-- Even though these two point to the same resource, have two states so the drawable will invalidate itself when coming out of pressed state. -->
<item android:state_focused="true"  android:state_enabled="false" android:state_pressed="true" android:drawable="@drawable/list_selector_disabled_holo_light" />
<item android:state_focused="true"  android:state_enabled="false" android:drawable="@drawable/list_selector_disabled_holo_light" />
<item android:state_focused="true"  android:state_pressed="true" android:drawable="@color/transparent" />
<item android:state_focused="false" android:state_pressed="true" android:drawable="@color/transparent" />
<item android:state_focused="true"  android:drawable="@drawable/list_focused_holo" />

然后设置code

listView.setSelector(R.drawable.my_transparent_selector);

XML attribute

android:listSelector
于 2013-10-12T07:15:01.327 回答
0

我刚刚将以下内容添加到我的列表视图中,我的问题解决了:

android:listSelector="@android:color/transparent"
于 2013-10-13T07:55:29.640 回答