【发布时间】:2014-05-02 11:20:28
【问题描述】:
我已经生成了一个 Slider ListView。目前,我可以突出显示所选片段的行并保持突出显示。我还有一个view 元素,目前没有设置为任何颜色。单击 ListView 时,我想用橙色突出显示此视图。我怎样才能做到这一点?我用来突出显示 Listview 行的代码如下;请逐步指导我。
listselector.xml
<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item android:drawable="@drawable/list_item_bg_normal" android:state_activated="false"/>
<item android:drawable="@drawable/list_item_bg_pressed" android:state_pressed="true"/>
<item android:drawable="@drawable/list_item_bg_pressed" android:state_activated="true"/>
</selector>
list_item_bg_pressed
<shape xmlns:android="http://schemas.android.com/apk/res/android"android:shape="rectangle">
<gradient
android:startColor="@color/list_background_pressed"
android:endColor="@color/list_background_pressed"
android:angle="90" />
</shape>
list_itm_bg_normal
<shape xmlns:android="http://schemas.android.com/apk/res/android"
android:shape="rectangle">
<gradient
android:startColor="@color/list_background"
android:endColor="@color/list_background"
android:angle="90" />
</shape>
activity_main.xml
<ListView
android:id="@+id/left_drawer"
android:listSelector="@drawable/list_selector"
android:background="@color/list_background"
android:layout_width="240dp"
android:layout_height="match_parent"
android:layout_gravity="start"
android:choiceMode="singleChoice"
android:divider="@android:color/transparent"
android:dividerHeight="0dp"
/>
【问题讨论】:
-
将选择器设置为所需的视图
-
@Ann 在下面检查我的答案,我可以突出显示 ListView 行。
-
@Raghunandan ...谢谢它的工作原理