问题描述
我试图用NavigationView实施NavigationDrawer。我已经通过设置组ID在菜单中添加的分隔符。但是我看不到的分隔符。我想这是因为分隔符的颜色是一样的背景。所以我想改变分离颜色。不过,我觉得没有办法改变它。谁能帮我?
在截图中,似乎有历史之间的空间分隔
和设置
,但你不能看到吧。
activity_main.xml
< XML版本=1.0编码=UTF-8&GT?;
< android.support.v4.widget.DrawerLayout
的xmlns:机器人=http://schemas.android.com/apk/res/android
的xmlns:工具=http://schemas.android.com/tools
的xmlns:程序=http://schemas.android.com/apk/res-auto
机器人:ID =@ + ID / drawer_layout
机器人:layout_width =match_parent
机器人:layout_height =match_parent
机器人:方向=垂直
机器人:fitsSystemWindows =真
工具:上下文=ui.MapActivity。>
<的LinearLayout
机器人:ID =@ + ID / main_content
机器人:layout_width =match_parent
机器人:layout_height =match_parent
机器人:方向=垂直>
<包括布局=@布局/ toolbar_actionbar/>
<! - 主要内容 - >
< / LinearLayout中>
< android.support.design.widget.NavigationView
机器人:layout_width =WRAP_CONTENT
机器人:layout_height =match_parent
机器人:layout_gravity =开始
机器人:背景=@色/ navdrawer_background
应用程序:insetForeground =#4000
应用程序:itemTextColor =@色/ navdrawer_item_text_color
应用程序:itemIconTint =@色/ navdrawer_item_icon_tint
应用程序:headerLayout =@布局/ drawer_header
应用程序:菜单=@菜单/抽屉/>
< /android.support.v4.widget.DrawerLayout>
drawer.xml
< XML版本=1.0编码=UTF-8&GT?;
<菜单的xmlns:机器人=http://schemas.android.com/apk/res/android>
<组机器人:ID =@ + ID / group_feature
机器人:checkableBehavior =单一>
<项目机器人:ID =@ + ID / navdrawer_item_map
机器人:检查=真
机器人:图标=@可绘制/ ic_drawer_map
机器人:标题=@字符串/ navdrawer_item_map/>
<项目机器人:ID =@ + ID / navdrawer_item_favourite
机器人:图标=@可绘制/ ic_drawer_fav
机器人:标题=@字符串/ navdrawer_item_fav/>
<项目机器人:ID =@ + ID / navdrawer_item_history
机器人:图标=@可绘制/ ic_drawer_history
机器人:标题=@字符串/ navdrawer_item_history/>
< /组>
<组机器人:ID =@ + ID / group_settings
机器人:checkableBehavior =单一>
<项目机器人:ID =@ + ID / navdrawer_item_settings
机器人:图标=@可绘制/ ic_drawer_settings
机器人:标题=@字符串/ navdrawer_item_settings/>
<项目机器人:ID =@ + ID / navdrawer_item_help
机器人:图标=@可绘制/ ic_drawer_help
机器人:标题=@字符串/ navdrawer_item_help/>
<项目机器人:ID =@ + ID / navdrawer_item_about
机器人:图标=@可绘制/ ic_drawer_about
机器人:标题=@字符串/ navdrawer_item_about/>
< /组>
< /菜单>
刚申请下style.xml行
<项目名称=机器人:listDivider> your_color< /项目>
下面就是信息,你的知识...... 如果你看过设计支持库。他们使用的是以下布局NavigationView seprator ..
<的FrameLayout的xmlns:机器人=http://schemas.android.com/apk/res/android
机器人:layout_width =match_parent
机器人:layout_height =WRAP_CONTENT>
<查看机器人:layout_width =match_parent
机器人:layout_height =1DP
机器人:背景=机器人:ATTR / listDivider/>
< /的FrameLayout>
在这里,你可以看到机器人:背景=机器人:ATTR / listDivider ..因此,享受...这里是我的输出,我改变颜色,holo_blue
I'm trying to use NavigationView to implement NavigationDrawer. I have added the separator by setting group id in menu. However I can't see the separator. I guess it is because the separator color is same as the background. So I want to change the separator color. But I find no way to change it. Can anyone help me?
In screenshot, it seems have a room for separator between History
and Settings
, but you can't see it.
activity_main.xml
<?xml version="1.0" encoding="utf-8"?>
<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_layout"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
android:fitsSystemWindows="true"
tools:context=".ui.MapActivity">
<LinearLayout
android:id="@+id/main_content"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
<include layout="@layout/toolbar_actionbar" />
<!--main content-->
</LinearLayout>
<android.support.design.widget.NavigationView
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:layout_gravity="start"
android:background="@color/navdrawer_background"
app:insetForeground="#4000"
app:itemTextColor="@color/navdrawer_item_text_color"
app:itemIconTint="@color/navdrawer_item_icon_tint"
app:headerLayout="@layout/drawer_header"
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:id="@+id/group_feature"
android:checkableBehavior="single">
<item android:id="@+id/navdrawer_item_map"
android:checked="true"
android:icon="@drawable/ic_drawer_map"
android:title="@string/navdrawer_item_map"/>
<item android:id="@+id/navdrawer_item_favourite"
android:icon="@drawable/ic_drawer_fav"
android:title="@string/navdrawer_item_fav"/>
<item android:id="@+id/navdrawer_item_history"
android:icon="@drawable/ic_drawer_history"
android:title="@string/navdrawer_item_history"/>
</group>
<group android:id="@+id/group_settings"
android:checkableBehavior="single">
<item android:id="@+id/navdrawer_item_settings"
android:icon="@drawable/ic_drawer_settings"
android:title="@string/navdrawer_item_settings"/>
<item android:id="@+id/navdrawer_item_help"
android:icon="@drawable/ic_drawer_help"
android:title="@string/navdrawer_item_help"/>
<item android:id="@+id/navdrawer_item_about"
android:icon="@drawable/ic_drawer_about"
android:title="@string/navdrawer_item_about"/>
</group>
</menu>
just apply following line on style.xml
<item name="android:listDivider">your_color</item>
The below is just information for your knowledge ...If you have seen design support library .. they are using following layout for NavigationView seprator..
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="wrap_content">
<View android:layout_width="match_parent"
android:layout_height="1dp"
android:background="?android:attr/listDivider"/>
</FrameLayout>
here, you can see android:background="?android:attr/listDivider" ..So enjoy ...and here is my output that i change color to holo_blue
这篇关于我怎样才能改变NavigationView分离器的颜色?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!