Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Add one section separator for Navigation Drawer in Android

I have a navigation drawer like this image. I want to add a section separator . It seems simple but I can't find anything on the web that was useful for my case.

- Add a line separator below Express

Add a line separator below My Information

enter image description here

        <menu xmlns:android="http://schemas.android.com/apk/res/android">
<item android:title="Express">
    <menu>
        <group
            android:id="@+id/me"
            android:checkableBehavior="single">
            <item
                android:id="@+id/nav_balance_transfer"
                android:icon="@mipmap/icon_wallet_transfer"
                android:title="Balance Transfer" />

            <item
                android:id="@+id/nav_load_money"
                android:icon="@mipmap/icon_load_money"
                android:title="Load Money" />
            <item
                android:id="@+id/nav_report"
                android:icon="@mipmap/icon_history"
                android:title="Report" />
        </group>
    </menu>
</item>
<item android:title="My Information">
    <menu>

        <group
            android:id="@+id/menu_nav_temp_gid"
            android:checkableBehavior="none">
            <item
                android:id="@+id/nav_profile"
                android:icon="@mipmap/icon_profile"
                android:title="My Account" />
            <item
                android:id="@+id/nav_changePassword"
                android:icon="@mipmap/icon_change"
                android:title="Change Password" />
            <item
                android:id="@+id/nav_ViewUser"
                android:icon="@mipmap/ic_view_user"
                android:title="View User" />
            <item
                android:id="@+id/nav_addUser"
                android:icon="@mipmap/icon_adduser"
                android:title="Add User" />
            <item
                android:id="@+id/nav_addScheme"
                android:icon="@mipmap/icon_add_scheme"
                android:title="Add Scheme" />

            <item
                android:id="@+id/nav_logout"
                android:icon="@mipmap/icon_logout"
                android:title="Log Out" />

        </group>
    </menu>
</item>

i had done this code if i takes express and my info in a separate group than it takes padding

suggest me how to achive this ..

like image 631
Tufan Avatar asked Aug 16 '16 11:08

Tufan


1 Answers

Try this....

    <group>
    <item android:title="Express">
    </item>
    </group>



            <group
                android:id="@+id/grpid1"
                android:checkableBehavior="single">
                <item
                    android:id="@+id/nav_balance_transfer"
                    android:icon="@mipmap/ic_launcher"
                    android:title="Balance Transfer" />

                <item
                    android:id="@+id/nav_load_money"
                    android:icon="@mipmap/ic_launcher"
                    android:title="Load Money" />
                <item
                    android:id="@+id/nav_report"
                    android:icon="@mipmap/ic_launcher"
                    android:title="Report" />
            </group>



    <group>
    <item android:title="My Information">



        </item>
    </group>


            <group
                android:id="@+id/grpid2"
                android:checkableBehavior="none">
                <item
                    android:id="@+id/nav_profile"
                    android:icon="@mipmap/ic_launcher"
                    android:title="My Account" />
                <item
                    android:id="@+id/nav_changePassword"
                    android:icon="@mipmap/ic_launcher"
                    android:title="Change Password" />
                <item
                    android:id="@+id/nav_ViewUser"
                    android:icon="@mipmap/ic_launcher"
                    android:title="View User" />
                <item
                    android:id="@+id/nav_addUser"
                    android:icon="@mipmap/ic_launcher"
                    android:title="Add User" />
                <item
                    android:id="@+id/nav_addScheme"
                    android:icon="@mipmap/ic_launcher"
                    android:title="Add Scheme" />

                <item
                    android:id="@+id/nav_logout"
                    android:icon="@mipmap/ic_launcher"
                    android:title="Log Out" />

            </group>


    </menu>

It looks like you just need to give your group tags unique ID's.

<group android:id="@+id/ids">
    <!-- Divider will appear above this item -->
    <item ... />
</group>

enter image description here

Sure @Tufan I can solve this problem also

Do this... put these lines to your dimen.xml

<dimen name="design_navigation_padding_top_default" tools:override="true">0dp</dimen>
<dimen name="design_navigation_separator_vertical_padding" tools:override="true">0dp</dimen>
<dimen name="design_navigation_padding_bottom" tools:override="true">0dp</dimen>

dimen.xml

<resources
    xmlns:tools="http://schemas.android.com/tools"
    >

    <dimen name="design_navigation_padding_top_default" tools:override="true">0dp</dimen>
    <dimen name="design_navigation_separator_vertical_padding" tools:override="true">0dp</dimen>
    <dimen name="design_navigation_padding_bottom" tools:override="true">0dp</dimen>
    <dimen name="navigation_separator_vertical_padding">0dp</dimen>

</resources>

New Screenshot remove padding by add this..

enter image description here

like image 160
Arjun saini Avatar answered Oct 08 '22 09:10

Arjun saini