安卓:setselector颜色列表视图不工作 [英] Android: setselector color for listview not working
问题描述
我在,我用下面的code设置选择的颜色列表视图活动。但是,当我选择一个项目,整个名单被突出显示与选择的颜色,这是我不想要的。我在哪里做错了吗?任何帮助是AP preciated。
的ListView LV = getListView();
lv.setFocusableInTouchMode(真正的);
lv.setBackgroundColor(Color.WHITE);
lv.setSelector(R.color.blue);
使用这种方式来使用选择
创建于 RES一个XML /绘制
,并为不同的事件状态
然后这个XML作为选择
例如,让 RES /绘制/ selector.xml
< XML版本=1.0编码=UTF-8&GT?;
<选择的xmlns:机器人=http://schemas.android.com/apk/res/android>
<项目安卓state_selected =真
机器人:可绘制=@彩色/灰度/>
< /选择器>
然后在宣布灰色的资源\值\ colors.xml
<颜色名称=灰色>#808080< /彩色>
然后设置选择为
lv.setSelector(R.drawable.selector);
I have a listview activity in which I set the selector color using the following code. But when I select an item, the whole list gets highlighted with the selector color, which I don't want. Where Am I doing wrong? Any help is appreciated.
ListView lv = getListView();
lv.setFocusableInTouchMode(true);
lv.setBackgroundColor(Color.WHITE);
lv.setSelector(R.color.blue);
Use this way to use Selector
Create a xml in res/drawable
and set the color for different event state
Then this xml as Selector
For example, let res/drawable/selector.xml
<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item android:state_selected="true"
android:drawable="@color/gray" />
</selector>
Then declare gray in your res\values\colors.xml
<color name="gray">#808080</color>
Then set selector as
lv.setSelector( R.drawable.selector);
这篇关于安卓:setselector颜色列表视图不工作的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!