我試圖爲NavigationView
創建一個自定義選擇器,但它沒有效果。這是我的代碼:app:itemBackground屬性不能按預期工作
<android.support.design.widget.NavigationView
android:id="@+id/nav_view"
android:layout_height="match_parent"
android:layout_width="wrap_content"
android:layout_gravity="start"
android:fitsSystemWindows="true"
app:headerLayout="@layout/nav_header"
app:menu="@menu/drawer_view"
app:itemBackground="@drawable/state_list_drawer_background" />
和選擇是state_list_drawer_background.xml
,下面的代碼:
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<!-- Checked state -->
<item android:drawable="@drawable/background_checked" android:state_checked="true" />
<!-- This is the default background color -->
<item android:drawable="@drawable/background_normal" />
</selector>
我能看到的不是自定義選擇透明的選擇。然後,我發現了一個限制爲NavigationView
如記錄here:
爲NavigationView的itemBackground屬性不正確處理項目的選中狀態:要麼不知何故所有項目被突出顯示,或者都不是。這使得這個屬性基本上不適用於大多數應用程序。
但是,在一些開發者能夠設置自定義選擇器,例如tTorrent應用程序在黑暗主題。我想知道他們是如何做到的!
任何人都可以幫助我解決這個問題嗎?
在此先感謝。
嘗試使用'應用:itemIconTint = 「@顏色/重音」 app:itemTextColor =「#FFFFFF」'。我知道這不是你想要的,但mahbe它有助於解決問題。 –