【发布时间】:2014-09-02 21:45:38
【问题描述】:
这很奇怪。我已经tried this steps given.
但似乎没有运气。 每当我单击 ListView 内的项目时, 该项目以黑色突出显示。而不是蓝色。 我错了哪一部分?
这是我的 activity_chat1.xml 文件:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical" >
<TextView
android:id="@+id/textView1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Available Peers"
android:textAppearance="?android:attr/textAppearanceLarge" />
<TextView
android:id="@+id/textView2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Pick one of the peers below : " />
<ListView
android:id="@+id/listView1"
android:layout_width="match_parent"
android:layout_height="128dp"
android:listSelector="@layout/list_selection"
android:choiceMode="singleChoice" />
<Button
android:id="@+id/btn_startchat"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Start to Chat" />
</LinearLayout>
这是我的 list_selection.xml 文件:
<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android" >
<item android:drawable="@color/pressed_color" android:state_pressed="true"/>
<item android:drawable="@color/checked_color" android:state_selected="true"/>
</selector>
这是我的 color.xml 文件:(在 res/values 目录下)
<?xml version="1.0" encoding="utf-8"?>
<resources>
<color name="pressed_color">#4d90fe</color>
<color name="checked_color">#ffffff</color>
<color name="activated_color">#ffffff</color>
</resources>
【问题讨论】:
-
你能不能把list_selection.xml放到drawable文件夹里?
-
然后改成android:listSelector="@drawable/list_selection"
-
有什么区别?内容还是一样的。 @user3249477
标签: java android xml listview highlight