我使用SimpleAdapter生成了Listview。我想在点击它时用一种颜色突出显示我的行,并希望保持突出显示直到另一行被点击。我做了以下但是没有帮助。我是新手,所以请一步一步指导我。我的代码如下:
可绘制文件夹中的Selector sel.xml
<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item android:drawable="@android:color/black" android:state_activated="false"/>
<item android:drawable="@android:color/black" android:state_activated="false" android:state_pressed="false"/>
<item android:drawable="@android:color/black" android:state_pressed="true"/>
<item android:drawable="@android:color/black" android:state_activated="true"/>
</selector>
listview xml
<com.fortysevendeg.swipelistview.SwipeListView
android:id="@+id/swipy"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
swipe:swipeFrontView="@+id/front"
swipe:swipeBackView="@+id/back"
android:listSelector="@color/blue2"
swipe:swipeMode="right"
/>
答案 0 :(得分:2)
使用
listView.setChoiceMode(ListView.CHOICE_MODE_SINGLE)
和选择器将
<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item android:drawable="@android:color/black" android:state_activated="false"/>
<item android:drawable="@android:color/black" android:state_activated="false" android:state_pressed="false"/>
<item android:drawable="@android:color/black" android:state_pressed="true"/>
<item android:drawable="@android:color/black" android:state_activated="true"/>
</selector>
你的列表视图
<ListView
android:id="@+id/my_list_view"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:choiceMode="singleChoice"
android:dividerHeight="1dp"
android:drawSelectorOnTop="true"
android:fadeScrollbars="true"
android:fastScrollEnabled="true"
android:focusable="true"
android:focusableInTouchMode="true"
android:scrollbarFadeDuration="100"
android:scrollbars="vertical" />
答案 1 :(得分:1)
示例:
<ListView
android:id="@+id/listview"
android:dividerHeight="3dp"
android:divider="#000000"
android:cacheColorHint="#05806D"
android:listSelector="#808080"
android:choiceMode="singleChoice"
android:text="No Details found"
android:layout_width="fill_parent"
android:layout_height="match_parent" >
您可以在android:listSelector="@drawable/list_selector"
或android:listSelector="Your color code"