How do I set padding for items inside NavigationView.I need to set paddingLeft for items as I have removed icons.What i have tried is this but it is not working:
<android.support.v4.widget.DrawerLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:id="@+id/drawer_layout"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:fitsSystemWindows="true"
tools:openDrawer="start">
<android.support.design.widget.NavigationView
android:id="@+id/nav_view"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:layout_gravity="start"
android:fitsSystemWindows="true"
android:focusable="true"
android:foreground="?attr/selectableItemBackground"
app:headerLayout="@layout/nav_header_navigation_drawer"
app:itemBackground="@drawable/selected_background"
app:itemTextAppearance="@style/Drawer"
app:menu="@menu/activity_navigation_drawer_drawer" />
My Drawer.xml file in styles:
<style name="Drawer">
<item name="android:listPreferredItemPaddingLeft">50dp</item>
<item name="android:textSize">30sp</item>
<item name="android:typeface">serif</item>
</style>
In case anyone wants to adjust the padding for the items in the NavigationDrawer using the latest material design, checkout these new attributes app:itemIconPadding and app:itemHorizontalPadding.
app:itemIconPadding will adjust the padding between your icon and the item's text app:itemHorizontalPadding, as its name suggest, will adjust the padding from the left and right horizontally for the item.
<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="true"
app:itemIconPadding="16dp"
app:itemHorizontalPadding="10dp"
app:menu="@menu/nav_drawer_menu" />`
Since you are using a menu without icons you can use the app:itemHorizontalPadding
attribute:
<com.google.android.material.navigation.NavigationView
app:itemHorizontalPadding="2dp"
../>
The result with default value and custom value:
Use the app:itemShapeInsetStart="0dp"
to change the margin of the shape:
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With