如何在navdrawer添加水平分隔符? [英] How add horizontal separator in navdrawer?

查看:131
本文介绍了如何在navdrawer添加水平分隔符?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用navdrawer与支持 android.support.design.widget.NavigationView

我想补充群体之间的分隔符(第设置,或者,它不是一个问题),但我找不到网络的方法。感谢您的支持

base_layout.xml

 < android.support.v4.widget.DrawerLayout的xmlns:机器人=htt​​p://schemas.android.com/apk/res/android
    的xmlns:工具=htt​​p://schemas.android.com/tool​​s
    的xmlns:程序=htt​​p://schemas.android.com/apk/res-auto
    机器人:ID =@ + ID /抽屉
    机器人:layout_width =match_parent
    机器人:layout_height =match_parent
    机器人:fitsSystemWindows =真
    工具:上下文=MainActivity。>    <的LinearLayout
        机器人:layout_height =match_parent
        机器人:layout_width =match_parent
        机器人:方向=垂直
        >
        <包括
            机器人:ID =@ + ID /工具栏
            布局=@布局/工具栏
            />
        <的FrameLayout
            机器人:ID =@ + ID /帧
            机器人:layout_width =match_parent
            机器人:layout_height =match_parent>        < /&的FrameLayout GT;    < / LinearLayout中>
    <! -
        如果您需要标头:
        应用:headerLayout =@布局/ drawer_header
     - >
    < android.support.design.widget.NavigationView
        机器人:ID =@ + ID / navigation_view
        机器人:layout_height =match_parent
        机器人:layout_width =WRAP_CONTENT
        机器人:layout_gravity =开始
        应用:菜单=@菜单/抽屉
        />
< /android.support.v4.widget.DrawerLayout>

drawer.xml

 <?XML版本=1.0编码=UTF-8&GT?;
<菜单的xmlns:机器人=htt​​p://schemas.android.com/apk/res/android>    <组机器人:checkableBehavior =单一>        <项目
            机器人:ID =@ + ID /家
            安卓:检查=假
            机器人:图标=@绘制/ ic_home_black_24dp
            机器人:标题=@字符串/ list_home/>        <项目
            机器人:ID =@ + ID / list_event
            安卓:检查=假
            机器人:图标=@绘制/ ic_list_black_24dp
            机器人:标题=@字符串/ list_event/>    < /组>    <组机器人:checkableBehavior =单一>        <项目
            机器人:ID =@ + ID /设置
            安卓:检查=假
            机器人:图标=@绘制/ ic_settings_black_24dp
            机器人:标题=@字符串/设置/>    < /组>&所述; /菜单>

我也尝试添加视图drawer.xml但没有成功(根本算不了什么显示为分):

 <?XML版本=1.0编码=UTF-8&GT?;
<菜单的xmlns:机器人=htt​​p://schemas.android.com/apk/res/android>    <组机器人:checkableBehavior =单一>        <项目
            机器人:ID =@ + ID /家
            安卓:检查=假
            机器人:图标=@绘制/ ic_home_black_24dp
            机器人:标题=@字符串/ list_home/>        <项目
            机器人:ID =@ + ID / list_event
            安卓:检查=假
            机器人:图标=@绘制/ ic_list_black_24dp
            机器人:标题=@字符串/ list_event/>    < /组>    <查看
        机器人:layout_width =FILL_PARENT
        机器人:layout_height =10dp
        机器人:背景=#000000/>    <组机器人:checkableBehavior =单一>        <查看
            机器人:layout_width =FILL_PARENT
            机器人:layout_height =10dp
            机器人:背景=#000000/>        <项目
            机器人:ID =@ + ID /设置
            安卓:检查=假
            机器人:图标=@绘制/ ic_settings_black_24dp
            机器人:标题=@字符串/设置/>    < /组>
&所述; /菜单>


解决方案

您需要不同的ID添加到您的群体,如:

 <组机器人:ID =@ + ID /组1><组机器人:ID =@ + ID /组2>

等。


编辑:
关于高度,我不知道,如果它的工作,但你可以尝试添加到您的 styles.xml 而这种风格应用到你的 NavigationView 使用风格=@风格/ MyNavigationView安卓主题=@风格/ MyNavigationView

 <样式名称=MyNavigationView父=Widget.Design.NavigationView>
    <项目名称=机器人:dividerHeight> 10dp< /项目>
< /风格>

I'm using navdrawer with support of android.support.design.widget.NavigationView

I'd like to add a separator between groups (or first of "settings", it's not a problem), but I cannot find a method in web. Thank you for your support

base_layout.xml

<android.support.v4.widget.DrawerLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    android:id="@+id/drawer"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:fitsSystemWindows="true"
    tools:context=".MainActivity">

    <LinearLayout
        android:layout_height="match_parent"
        android:layout_width="match_parent"
        android:orientation="vertical"
        >
        <include
            android:id="@+id/toolbar"
            layout="@layout/toolbar"
            />
        <FrameLayout
            android:id="@+id/frame"
            android:layout_width="match_parent"
            android:layout_height="match_parent">

        </FrameLayout>

    </LinearLayout>
    <!--
        IF YOU NEED HEADER:
        app:headerLayout="@layout/drawer_header"
    -->
    <android.support.design.widget.NavigationView
        android:id="@+id/navigation_view"
        android:layout_height="match_parent"
        android:layout_width="wrap_content"
        android:layout_gravity="start"
        app:menu="@menu/drawer"
        />
</android.support.v4.widget.DrawerLayout>

drawer.xml

<?xml version="1.0" encoding="utf-8"?>
<menu xmlns:android="http://schemas.android.com/apk/res/android">

    <group android:checkableBehavior="single">

        <item
            android:id="@+id/home"
            android:checked="false"
            android:icon="@drawable/ic_home_black_24dp"
            android:title="@string/list_home" />

        <item
            android:id="@+id/list_event"
            android:checked="false"
            android:icon="@drawable/ic_list_black_24dp"
            android:title="@string/list_event" />

    </group>

    <group android:checkableBehavior="single">

        <item
            android:id="@+id/settings"
            android:checked="false"
            android:icon="@drawable/ic_settings_black_24dp"
            android:title="@string/settings" />

    </group>

</menu>

I did try to add View to drawer.xml but without success (simply nothing appear as divider):

<?xml version="1.0" encoding="utf-8"?>
<menu xmlns:android="http://schemas.android.com/apk/res/android">

    <group android:checkableBehavior="single">

        <item
            android:id="@+id/home"
            android:checked="false"
            android:icon="@drawable/ic_home_black_24dp"
            android:title="@string/list_home" />

        <item
            android:id="@+id/list_event"
            android:checked="false"
            android:icon="@drawable/ic_list_black_24dp"
            android:title="@string/list_event" />

    </group>

    <View
        android:layout_width="fill_parent"
        android:layout_height="10dp"
        android:background="#000000"/>

    <group android:checkableBehavior="single">

        <View
            android:layout_width="fill_parent"
            android:layout_height="10dp"
            android:background="#000000"/>

        <item
            android:id="@+id/settings"
            android:checked="false"
            android:icon="@drawable/ic_settings_black_24dp"
            android:title="@string/settings" />

    </group>




</menu>

解决方案

You need to add different id's to your groups, like:

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

<group android:id="@+id/group2">

etc.


EDIT: About height, I'm not sure if it work, but you can try add this to your styles.xml and apply this style to your NavigationView using style="@style/MyNavigationView" or android:theme="@style/MyNavigationView":

<style name="MyNavigationView" parent="Widget.Design.NavigationView">
    <item name="android:dividerHeight">10dp</item>
</style>

这篇关于如何在navdrawer添加水平分隔符?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆