简体   繁体   English

如何更改设计支持库的导航抽屉菜单项布局的部分

[英]How to change parts of the Navigation Drawer menu-item layouts of the Design Support Library

I am talking about the Design Support Library here. 我在这里谈论设计支持库 I am trying to change things like: 我正在尝试更改以下内容:

  • selected menu-item background color 选定的菜单项背景色
  • distance between icon and text 图标与文字之间的距离

I tried a lot but I can seem to find any solutions for these problems. 我做了很多尝试,但似乎可以找到解决这些问题的任何方法。 You can select the menu-item but somehow instead of only the selected item changing the background color (with xml attribute state-pressed ), everything in the menu is getting the color I set in itemBackground . 您可以选择菜单项,但是以某种方式而不是仅更改选定的项目来更改背景色(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"/>

And here is drawer_background_selector : 这是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>

For the second problem, I want to decrease the distance between the icon and text but somehow I can't find any way to do this while using the Support Library provided by google. 对于第二个问题,我想减小图标与文本之间的距离,但是在使用google提供的支持库时,我不知何故无法做到这一点。

Any ideas? 有任何想法吗? Or do I have to go with a library like the MaterialDrawer github library. 还是我必须使用像MaterialDrawer github库这样的库。 Problem with this is that I am afraid of the future in which the Design Support library might be updated but this library might not. 问题在于,我担心将来可能会更新设计支持库,但可能不会更新。

You can override the dimens values, and even the layout files. 您可以覆盖调暗值,甚至覆盖布局文件。 The only thing I'm still maybe stuck on is subheader padding). 我唯一仍然可能遇到的问题是子标题填充)。

eg you can override 例如,您可以覆盖

    <dimen tools:override="true" name="design_navigation_icon_padding">5dp</dimen>

code here 这里的代码

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM