我在这里谈论的是设计支持库。我正在尝试更改以下内容:
- 选定的菜单项背景颜色
- 图标和文字之间的距离
我尝试了很多,但我似乎可以找到解决这些问题的任何方法。您可以选择菜单项,但不知何故,而不是仅更改背景颜色的选定项(使用 xml 属性state-pressed
),菜单中的所有内容都获得了我设置的颜色itemBackground
。
<android.support.design.widget.NavigationView
android:id="@+id/nvView"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:layout_gravity="start"
android:background="@android:color/white"
app:headerLayout='@layout/nav_header'
app:menu="@menu/drawer_view"
app:itemTextColor="@drawable/drawer_item_text"
app:itemBackground="@drawable/drawer_background_selector"
android:fitsSystemWindows="false"/>
这是drawer_background_selector
:
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item android:drawable="@color/black" android:state_pressed="true" />
<item android:drawable="@color/white"/>
</selector>
对于第二个问题,我想减少图标和文本之间的距离,但不知何故,在使用谷歌提供的支持库时我找不到任何方法来做到这一点。
有任何想法吗?还是我必须使用像MaterialDrawer github 库这样的库。问题是我担心设计支持库可能会更新但这个库可能不会更新。