我遇到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);
謝謝,但它不起作用:( – asmproger