Search code examples
androidnavigation-drawerandroid-navigationview

Customize Navigationview menu UI Android


I am using NavigationView control of android to create sliding drawer. All is fine except spacing between Menu Items in navigation view as shown in image.

Thank you in advance guysenter image description here

Navigationview

<android.support.design.widget.NavigationView
    android:id="@+id/navigation_view"
    android:layout_height="match_parent"
    android:layout_width="wrap_content"
    android:layout_gravity="start"
    app:headerLayout="@layout/homescreen_header"
    app:menu="@menu/homescreen_nav_drawer"

    app:itemIconTint="@color/green"
    app:itemTextColor="@color/White"
    app:theme="@style/NavigationView"
    app:itemBackground="@color/nav_item_bg"
    android:background="@color/nav_item_bg"
    />

<style name="NavigationView" >
    <item name="android:listDivider">@android:color/black</item>
</style>

Solution

  • create a style with

       <style name="NavigationViewStyle">
        <item name="android:listPreferredItemHeightSmall">25dp</item><!-- menu item height-->
    </style>
    

    and apply this style to NavigationView

     app:theme="@style/NavigationViewStyle"