简体   繁体   中英

How to draw a line between menu item in navigation drawer

I want to highlight navigation items like this:

导航菜单中突出显示的项目

But my current menu looks like this:

导航菜单中未突出显示的项目

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?

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM