java 如何在导航抽屉中的菜单项之间画一条线
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/38283373/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
How to draw a line between menu item in navigation drawer
提问by Dinesh Rijal
I want to highlight navigation items like this:
我想突出显示这样的导航项目:
But my current menu looks like this:
但我目前的菜单是这样的:
My menu.xml is
我的 menu.xml 是
<?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?
如何创建上述高光效果?
回答by Vucko
Give each group a unique id like this:
为每个组提供一个唯一的 id,如下所示:
<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 questionto see how to change the color of the divider.
编辑:由于线条现在显示但在黑色背景上是黑色的,请参阅此问题以了解如何更改分隔线的颜色。