如何在单击或选择时更改android列表项的颜色?
可能重复:如何在单击或选择时更改android列表项的颜色?,android,Android,可能重复: 朋友们 我想更改android列表项的颜色单击 有人告诉我应该使用哪个属性来实现此功能吗 实际上,当用户单击列表项时,他不知道是否单击了它 这是我的密码 <ListView android:id="@+id/android:list" android:layout_width="fill_parent" android:layout_height="wrap_content" android:drawSelectorOnTop="false"
朋友们 我想更改android列表项的颜色单击 有人告诉我应该使用哪个属性来实现此功能吗 实际上,当用户单击列表项时,他不知道是否单击了它 这是我的密码
<ListView android:id="@+id/android:list" android:layout_width="fill_parent"
android:layout_height="wrap_content" android:drawSelectorOnTop="false"
android:layout_below="@+id/Tablayoutdesign"
android:cacheColorHint="#000000"
android:dividerHeight="1dip"
android:layout_marginTop="63dip"
android:layout_marginBottom="40dip"
/>
步骤1:在ListView中添加android:listSelector属性,如下所示
<ListView android:id="@+id/android:list" android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_below="@+id/Tablayoutdesign"
android:cacheColorHint="#000000"
android:dividerHeight="1dip"
android:layout_marginTop="63dip"
android:layout_marginBottom="40dip"
/>
@UMMA:你的问题解决了吗,你到达目的地了吗?@UMMA:请告诉我,你出了什么错误?你能再继续吗,我错认为android:drawable=“android:drawable=@drawable/focused”,现在我编辑了,请检查编辑的回答焦点在这里的行为像cacheHintColor.pressed不起作用..按下时没有颜色变化:(@UMMA:您是否在drawable中创建了listselector.xml文件folder@UMMA:在drawable文件夹中创建list_selector.xml文件,并在folderi编辑的值下创建color.xml文件,我的答案,请参考我的Umar我也面临与您相同的问题..您如何克服此问题,请与我分享?请
<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<!-- Selected -->
<item
android:state_focused="true"
android:state_selected="false"
android:drawable="@drawable/focused"/>
<!-- Pressed -->
<item
android:state_selected="true"
android:state_focused="false"
android:drawable="@drawable/selected" />
</selector>
<resources>
<drawable name="focused">#ff5500</drawable>
<drawable name="selected">#FF00FF</drawable>
</resources>
ListView lv= (ListView) findViewById(R.id.list);
lv.setSelector( R.drawable.listselector);