How to Control Navigationview Margin Between Menu Items

Set the distance between the menu in a navigation drawer and the screen edge?

It worked for me:)

In NavigationView for Padding between the screen and the icon menu :

app:itemHorizontalPadding="40dp"

and for padding between the menu icon and the text use this:

app:itemIconPadding="28dp"

full code:

<com.google.android.material.navigation.NavigationView
android:id="@+id/nav_view"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_gravity="start"
android:background="@android:color/background_light"
android:fitsSystemWindows="true"
app:headerLayout="@layout/nav_header_main"
app:menu="@menu/activity_main_drawer"
app:itemTextColor="?android:textColorPrimary"
app:itemIconPadding="28dp"
app:itemHorizontalPadding="40dp" >

Reduce space between menu groups inside navigation drawer

I think you must override
design_navigation_separator_vertical_padding dimens in your project dimes.xml

 <dimen name="design_navigation_separator_vertical_padding" tools:override="true">0dp</dimen>

Setting a margin for NavigationDrawer items

Try this as item

<TextView xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="#fff"
android:padding="20dp"
android:textAppearance="?android:attr/textAppearanceLarge"
android:textColor="#222"
android:text="bla bla bla" />

and main xml as this

<android.support.v4.widget.DrawerLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_height="match_parent"
android:layout_width="match_parent"
android:id="@+id/drawer_layout">

<android.support.v4.widget.SwipeRefreshLayout

android:layout_height="match_parent"
android:layout_width="match_parent"
android:id="@+id/refreshSites"
tools:context=".MyActivity">

<android.support.v7.widget.RecyclerView
xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/sitesList"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="5dp"/>
</android.support.v4.widget.SwipeRefreshLayout>

<RelativeLayout
android:layout_width="280dp"
android:layout_height="fill_parent"
android:id="@+id/drawerPane"
android:layout_gravity="start">

<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">

<ListView android:id="@+id/left_drawer"
android:layout_width="280dp"
android:layout_height="match_parent"
android:layout_gravity="start"
android:choiceMode="singleChoice"
android:divider="@android:color/white"
android:dividerHeight="0dp"
android:background="#FFF">
</ListView>

</LinearLayout>
</RelativeLayout>

Hope, this will help.

Android NavigationView: reduce space between icon and text and `itemBackground` not working

After digging through the source. I found that you could override a dimension resource to fix this.

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

Beware though that this will change the dimension resource everywhere!
You may also be able to copy the layout file and override that instead design_navigation_menu.xml

As for the different color edges, I set app:itemBackground="@android:color/transparent" and then in the theme for the NavigationView set:

<item name="selectableItemBackground">@drawable/nav_drawer_item_selector</item>

You can handle both in the theme for your NavigationView as follows:

    <item name="selectableItemBackground">@drawable/nav_drawer_item_selector</item>
<item name="itemBackground">@color/transparent</item>

nav_drawer_item_selector.xml looks like so:

<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item android:state_pressed="true" android:drawable="@color/white_alpha_10" />
<item android:state_checked="true" android:drawable="@color/white_alpha_10" />
<item android:state_focused="true" android:drawable="@color/white_alpha_10" />
<item android:state_activated="true" android:drawable="@color/white_alpha_10" />
<item android:drawable="@color/transparent" />
</selector>

Change drawer gap between header group and first item menu

Thanks to azizbekian, his answer gived to me a great idea (maybe not the best but in my case more simple and fast to implement).
Basically, I add a layout with the same name (this will override it).
After that I change all that I need, so the result is this:

Sample Image

Sample Image



Related Topics



Leave a reply



Submit