5

I am currently developing an Android App with a support NavigationView. I have to question to make it as I want it: (1) I want to divide the navigation elements into two areas: one at top below the header and one at the bottom end. (2) I want to remove the padding between the divider and the element below it.

How it looks vs how it should look: How it looks vs how it should look

I know there is a way to override the padding value, which would fix (2). But this feels kind of dirty and maybe there is another approach to achieve both of this. My idea was to get the "Settings"-element and change its layout programmatically, but so far I didn't find a way to get that working. Or do I really have to build the footer myself?

Also, I am not quite sure what buzzwords I should be googling. Maybe there is already an easy answer out there.

My current code. Right now there are no layout changes inside the Activity, therefore I did not add it.

activity_main.xml:

<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/main_drawer_layout"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:fitsSystemWindows="true"
    tools:context=".main.MainActivity">

    <!-- The content -->
    <LinearLayout>...</LinearLayout>

    <!-- The navigation drawer -->
    <android.support.design.widget.NavigationView
        android:id="@+id/main_navigationview"
        android:layout_width="wrap_content"
        android:layout_height="match_parent"
        android:layout_gravity="start"
        android:background="@android:color/white"
        app:headerLayout="@layout/mainnav_header"
        app:itemBackground="@drawable/menu_background"
        app:itemIconTint="@color/menu_text"
        app:itemTextColor="@color/menu_text"
        app:menu="@menu/maindrawer">

    </android.support.design.widget.NavigationView>

</android.support.v4.widget.DrawerLayout>

menu.xml:

<menu xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto">

<group android:id="@+id/main_drawer_menu1" android:checkableBehavior="single">
    <item
        android:id="@+id/main_navigationview_request"
        android:checkable="false"
        android:enabled="false"
        android:icon="@drawable/ic_navigationdrawer_request"
        android:title="@string/main_navigation_request"
        app:actionLayout="@layout/menuitem_default" />
    <item
        android:id="@+id/main_navigationview_invitations"
        android:checked="true"
        android:icon="@drawable/ic_navigationdrawer_invitations"
        android:title="@string/main_navigation_invitations"
        app:actionLayout="@layout/menuitem_default" />
    <item
        android:id="@+id/main_navigationview_prev"
        android:icon="@drawable/ic_navigationdrawer_previous"
        android:title="@string/main_navigation_previnvites"
        app:actionLayout="@layout/menuitem_default" />
    <item
        android:id="@+id/main_navigationview_info"
        android:icon="@drawable/ic_navigationdrawer_info"
        android:title="@string/main_navigation_info"
        app:actionLayout="@layout/menuitem_default" />
</group>
<group android:id="@+id/main_drawer_menu2" android:checkableBehavior="single">
    <item
        android:id="@+id/main_navigationview_settings"
        android:checked="true"
        android:icon="@drawable/ic_navigationdrawer_settings"
        android:title="@string/main_navigation_settings"
        app:actionLayout="@layout/menuitem_default" />
    <item
        android:id="@+id/main_navigationview_logout"
        android:icon="@drawable/ic_navigationdrawer_logout"
        android:title="@string/main_navigation_logout"

        app:actionLayout="@layout/menuitem_caution" />
</group>

gtRfnkN
  • 489
  • 7
  • 19
  • can we have your code?? – Janki Gadhiya Jul 06 '16 at 10:14
  • of course, sorry. Currently it's just those 2 xml files. No layout changes are done inside the activity – gtRfnkN Jul 06 '16 at 10:23
  • I like the one on the right more, but that is not the problem I want to discuss. I just want to find a way to make the layout look like the one on the right side. – gtRfnkN Jul 06 '16 at 10:49
  • not possible..!! with default navigation drawer you can create a custom..!! – Janki Gadhiya Jul 06 '16 at 10:51
  • 2
    Check this answer: http://stackoverflow.com/a/30611068/1971522 and the whole question there. It supposes usage of the nested layout inside the NavigationView. It's pretty dirty approach, but it allows to achieve desired effect. – Artem Jul 06 '16 at 11:18
  • `NavigationView` has its own menu presenter implementation. It's not pluggable/replaceable and it's not very flexible either. I recommend you just code your own layout and forget about `NavigationView`. – kris larson Jul 06 '16 at 20:35
  • 1
    So I ended up building my own view for this navigation bar with 2 separate ListViews. Not my favorite solution, but it will do for now. If there is any new/better solution, I would love to hear it. – gtRfnkN Jul 25 '16 at 18:01

1 Answers1

2

This line remove padding between icon and text.

only add below line in dimen.xml file

<dimen tools:override="true" name="design_navigation_icon_padding">10dp</dimen>
Ankur Bavishi
  • 943
  • 12
  • 14