2013-05-29 72 views
0

我遇到ListView項目的問題。我正在使用listSelector。 我需要在按下時更改背景。但是當我按下它時,所有項目都會改變背景。它發生在Android 2.3.6上。在4.0.3以上,它運作良好。ListView項背景問題

ListSelector

<selector xmlns:android="http://schemas.android.com/apk/res/android" android:id="@+id/defaultSelector"> 
<item android:drawable="@color/defaultDashboardItemBackground" android:state_enabled="false" android:state_focused="true" android:state_pressed="false"/> 
<item android:drawable="@color/defaultDashboardItemHover" android:state_pressed="true"/> 
<item android:drawable="@color/defaultDashboardItemBackground" android:state_focused="true" android:state_pressed="false"/> 

一些代碼

ListView list = (ListView) act.findViewById(R.id.menu_listview); 
list.setBackgroundColor(act.getResources().getColor(getThemeBackground(theme))); 
list.setSelector(act.getResources().getDrawable(getThemeSelector(theme))); 
list.addHeaderView(createHeader("HEADER")); 
list.setAdapter(adap); 

回答

0

將此屬性設置爲您的ListView android:cacheColorHint="@null" 這可能有助於解決這個問題。

+0

謝謝,但它不起作用:( – asmproger

0
<ListView 
    android:id="@android:id/list" 
    android:layout_width="fill_parent" 
    android:layout_height="fill_parent" 
    android:cacheColorHint="#00000000" 
    android:listSelector="#00000000" 
    android:fadingEdge="none"/> 

而不要在ListView中定義背景顏色。 在listitem.xml根佈局中定義背景顏色(選擇器)或圖像(選擇器)。

希望這會幫助你。

+0

謝謝,但它不工作:( – asmproger