Change Navigation Drawer Icon and Text Spacing
Asked Answered
L

5

17

I am wondering how do we change the spacing between the icon and the text?

Is it doable?

Any thoughts?

Thank you

enter image description here

Lynlyncean answered 14/2, 2016 at 13:42 Comment(1)
A
1

You will need another layout which you will inflate. In the layout, you can set the margin to what you want. Inflater allows you to adapt a layout to a view. check this out http://developer.android.com/reference/android/view/LayoutInflater.html or this http://khajanpndey.blogspot.com.ng/2012/12/android-layoutinflater-tutorial.html

Whichever view you are using, checkout how you can inflate the view. Hope this help.

Allister answered 14/2, 2016 at 13:56 Comment(0)
P
19

Add the following line to app\src\main\res\values\dimens.xml file. No need to add new layout.

<dimen tools:override="true" name="design_navigation_icon_padding">5dp</dimen>
Prinz answered 4/3, 2017 at 11:15 Comment(1)
Works for me :)Primrosa
M
16

I added one line to xml: app:itemIconPadding="@dimen/space24" and it`s worked

<android.support.design.widget.NavigationView
    android:id="@+id/navigation_view"
    android:layout_width="wrap_content"
    android:layout_height="match_parent"
    android:layout_gravity="start"
    android:background="@android:color/white"
    android:clipToPadding="false"
    android:paddingBottom="@dimen/space48"
    app:headerLayout="@layout/layout_nav_header"
    app:insetForeground="@color/black"
    **app:itemIconPadding="@dimen/space24"**
    app:itemBackground="@drawable/background_selected_menu"
    app:itemHorizontalPadding="@dimen/horizontal_padding_on_nav_drawer"
    app:menu="@menu/drawer">
Murrain answered 17/10, 2018 at 11:0 Comment(0)
S
3

If you change in your dimens.xml file you'll change on all of your project. I suggest you to change locally, just in NavigationView, like Vadym purpouse. Or you can change there like that:

<com.google.android.material.navigation.NavigationView
    app:itemIconPadding="4dp"
    ../>

This worked perfectly to me, and you can just change the value of the padding to everthing that you want.

Sememe answered 7/8, 2020 at 19:4 Comment(0)
A
1

You will need another layout which you will inflate. In the layout, you can set the margin to what you want. Inflater allows you to adapt a layout to a view. check this out http://developer.android.com/reference/android/view/LayoutInflater.html or this http://khajanpndey.blogspot.com.ng/2012/12/android-layoutinflater-tutorial.html

Whichever view you are using, checkout how you can inflate the view. Hope this help.

Allister answered 14/2, 2016 at 13:56 Comment(0)
M
0

Here is the solution - app:itemIconPadding="15dp"

Example:

<com.google.android.material.navigation.NavigationView android:id="@+id/nav_view" android:layout_width="wrap_content" android:layout_height="match_parent" android:layout_gravity="start" android:fitsSystemWindows="false" app:itemIconPadding="15dp" app:itemIconSize="28dp" app:headerLayout="@layout/nav_header_main2" app:itemIconTint="@color/navigation_item_text_color" app:menu="@menu/activity_main_drawer" app:itemTextAppearance="@style/NavigationDrawerStyle" app:itemBackground="@color/white" />

Mayamayakovski answered 6/7, 2022 at 5:41 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.