我試圖在選擇它時設置列表中某個項目的顏色。即我的列表通常是灰色的,但我希望用戶選擇的項目在按下時發黃光。setSelector在使用ListActivity時會導致不希望的行爲
在onCreate
的方法,我試圖用getListView().setSelector(R.xml.list_pressed)
然而,這表明改變整個列表,而不是單個元素的背景顏色的古怪的行爲!我難以理解爲什麼會發生這種情況。
ListActivity
是TabActivity
的一部分,如果這有所影響。
謝謝。
編輯:這是list_pressed.xml
<?xml version="1.0" encoding="UTF-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item
android:state_enabled="false"
android:drawable="@color/darkgray" />
<item
android:state_pressed="true"
android:drawable="@color/yellow" />
<item
android:state_focused="true"
android:drawable="@color/darkgray" />
</selector>
你檢查了這個問題的答案嗎? http://stackoverflow.com/questions/2170531/change-selection-in-a-listview-from-orange-to-green –
我有,他們沒有幫助。 :( – Glitch
你能引用R.xml.list_pressed的內容嗎? – Graeme