Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to draw a line between menu item in navigation drawer

I want to highlight navigation items like this:

highlighted item in navigation menu

But my current menu looks like this:

not highlighted item in navigation menu

My menu.xml is

<?xml version="1.0" encoding="utf-8"?>
    <menu xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto">
    <group android:checkableBehavior="single">
    <group android:checkableBehavior="single">
        <item android:id="@+id/home"
            android:title="Home"
            android:icon="@drawable/ic_action_home_page"/></group>
    <group android:checkableBehavior="single">
        <item android:id="@+id/p_profile"
            android:title="Payment Profile"
            android:icon="@drawable/ic_action_payment_profile"/></group>
    <group android:checkableBehavior="single">
        <item android:id="@+id/p_history"
            android:title="Payment history"
            android:icon="@drawable/ic_action_payment_history"/></group>
    <group android:checkableBehavior="single">
        <item android:id="@+id/m_cards"
            android:title="My cards"
            android:icon="@drawable/ic_action_my_card"/></group>
        <group android:checkableBehavior="single">
            <item android:id="@+id/menu_friends"
                android:title="Friends"
                android:icon="@drawable/search_people"/></group>

    <group android:checkableBehavior="single">
        <item android:id="@+id/notification"
            android:title="Notification"
            android:icon="@drawable/ic_action_notification"/></group>
    <group android:checkableBehavior="single">
        <item android:id="@+id/about"
            android:title="About"
            android:icon="@drawable/ic_action_about_us"/></group>

    </group>
</menu>

How can I create the above highlight effect?

like image 601
Dinesh Rijal Avatar asked Nov 29 '22 14:11

Dinesh Rijal


1 Answers

Give each group a unique id like this:

<group android:checkableBehavior="single"
android:id="@+id/group1">

It'll draw those lines for you between any two groups.

EDIT: Since the line is now showing but it's black on the black background, refer to this question to see how to change the color of the divider.

like image 118
Vucko Avatar answered Dec 04 '22 14:12

Vucko