Joop
Joop

Reputation: 3788

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:

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.

<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:

<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.

Any ideas? Or do I have to go with a library like the MaterialDrawer github library. 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.

Upvotes: 1

Views: 761

Answers (1)

nAndroid
nAndroid

Reputation: 960

You can override the dimens values, and even the layout files. The only thing I'm still maybe stuck on is subheader padding).

e.g. you can override

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

code here

Upvotes: 2

Related Questions