我要解釋(或者至少嘗試)我想實現的目標,因爲這會讓我發瘋。激活/選擇ListView中的項目時更改視圖背景
我有一個ListView和項目具有以下佈局:
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:padding="10dp">
<FrameLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@drawable/item_background"
android:duplicateParentState="true" >
... some contents here...
</FrameLayout>
</FrameLayout>
「item_background.xml」包含一個選擇這樣的背景取決於項目的狀態發生改變。當我按下並釋放項目時它工作正常,但當我用DPAD /軌跡球「選擇」項目時它不工作。我嘗試了一切(state_activated,state_focused,state_selected ...),但沒有任何工作。我試圖尋找解決方案,但看起來像我無法找到適當的關鍵字來搜索。
任何想法?
謝謝!
您是否嘗試將背景(item_background)設置爲您的佈局(具有10dp填充)的根FrameLayout? – Devrim
我可以嘗試一下,以確保它在那裏有效。我會盡快完成。 –
我剛剛嘗試過,它不工作。現在我很困惑。 –