Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

create divider between header and menu in navigationview for drawerlayout

For a navigationview, we can create a divider between two items by putting them in two groups. But how can we create a divider between a header and menu? I tried to make an empty group at the top of the menu, but it doesn't work.

The default theme for navigationview looks quite cool, but I like the black & white style. But it looks quite awkward when I can't create a divider between the header and menu (sad)

enter image description here

like image 850
gw0 Avatar asked Sep 15 '16 01:09

gw0


1 Answers

I don't know what's the proper way to do it, but I have some workaround for it:

  1. As mentioned by P. Ilyin, you can put the divider on the bottom of your header view.

  2. You can add the divider onto the NavigationView layout, and manually adjusting the divider position.

    Example:

    <android.support.design.widget.NavigationView
        android:id="@+id/navigation_view"
        android:layout_width="wrap_content"
        android:layout_height="match_parent"
        android:layout_gravity="start"
        app:headerLayout="@layout/drawer_menu_header"
        app:menu="@menu/menu_drawer">
    
        <View
            android:layout_width="match_parent"
            android:layout_height="1dp"
            android:background="@color/background_gray"
            android:layout_marginTop="140dp"/>
    
    </android.support.design.widget.NavigationView>
    

    In this case, we make a custom gray line divider that has 1dp height, and it positioned under the menu header (140dp is the height of this menu header).

like image 182
Kharda Avatar answered Oct 22 '22 14:10

Kharda