aditi
aditi

Reputation: 21

set margin to menu item in navigation drawer but not header part

I have NavigationDrawerActivity. I want to set left margin to menu items.

I tried like this.

<style name="NavigationDrawerStyle" parent="AppTheme">
   <item name="android:layout_marginLeft">@dimen/dimen20dp</item>
</style>

and applied this style to NavigationView. Margin left is set to both header part and list. I want it to apply to only list.

Upvotes: 2

Views: 2067

Answers (1)

Gabriele Mariotti
Gabriele Mariotti

Reputation: 363687

Use app:itemIconPadding to change the margin between the icon and the text

<com.google.android.material.navigation.NavigationView
    app:itemIconPadding="xxdp"
    ..>

enter image description here

Use the app:itemHorizontalPadding to change the padding before the icon:

<com.google.android.material.navigation.NavigationView
    app:itemHorizontalPadding="0dp"
    />

enter image description here

Use app:itemShapeInsetStart to change the padding of the shape

<com.google.android.material.navigation.NavigationView
    app:itemShapeInsetStart="0dp"
    />

enter image description here

You can also use a custom style:

  <style name="CustomNavigationView" parent="Widget.MaterialComponents.NavigationView">
       <item name="itemIconPadding">@dimen/.....</item>
       <item name="itemHorizontalPadding">@dimen/....</item>
       <item name="itemShapeInsetStart">@dimen/..../item>
  </style>

Upvotes: 4

Related Questions