How to overcome this item padding in navigation drawer?
According to source code of NavigationView found here, it led me to NavigationMenuPresenter (found here) which says, every normal type in menu list inflates R.layout.design_navigation_item
. So if you preview it (here) you will notice what preference it uses.
<android.support.design.internal.NavigationMenuItemView
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="?attr/listPreferredItemHeightSmall"
android:paddingLeft="?attr/listPreferredItemPaddingLeft"
android:paddingRight="?attr/listPreferredItemPaddingRight"
android:foreground="?attr/selectableItemBackground"
android:focusable="true"/>
So, the final step is to override the style attribute, i.e. layout_height
which references to "?attr/listPreferredItemHeightSmall" (default 48dp)
.
Open your styles.xml and override it by i.e using custom value:
<!-- Base application theme. -->
<style name="AppTheme" parent="Theme.AppCompat.Light.DarkActionBar">
<!-- Customize your theme here. -->
<item name="colorPrimary">@color/colorPrimary</item>
<item name="colorPrimaryDark">@color/colorPrimaryDark</item>
<item name="colorAccent">@color/colorAccent</item>
<!-- HERE-->
<item name="listPreferredItemHeightSmall">18dp</item>
</style>
Original:
Custom:
Add this line to your dimens.xml file and customize this DP as per your need i have solved my problem by this lines.
<dimen name="design_navigation_padding_top_default" tools:override="true">5dp</dimen>
<dimen name="design_navigation_separator_vertical_padding" tools:override="true">0dp</dimen>
<dimen name="design_navigation_padding_bottom" tools:override="true">5dp</dimen>
<dimen name="design_navigation_icon_size" tools:override="true">20dp</dimen>
<dimen name="design_navigation_icon_padding" tools:override="true">12dp</dimen>