我正在尝试为 创建一个自定义选择器NavigationView
,但它没有效果。这是我的代码:
<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
记录的限制:
NavigationView 的 itemBackground 属性无法正确处理项目的选中状态:不知何故,要么所有项目都突出显示,要么都不突出。这使得该属性对于大多数应用程序基本上无法使用。
但是,一些开发人员能够设置自定义选择器,例如黑暗主题上的tTorrent应用程序。我想知道他们怎么能做到!
谁能帮我解决这个问题?
提前致谢。