我试图为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它有助于解决问题。 –