如何添加分隔符菜单项? [英] How to add separator in menu items?
问题描述
我需要添加抽屉式导航
菜单项之间的分隔符。
I need to add a separator between Navigation Drawer
menu items.
code为 NavigationDrawer
<android.support.design.widget.NavigationView
android:id="@+id/navigationView"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:layout_gravity="start"
android:background="@color/colorPrimary"
android:fitsSystemWindows="true"
android:theme="@style/NavigationTheme"
custom:headerLayout="@layout/drawer_header"
custom:menu="@menu/drawer_view" />
drawer_view.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/nav_home"
android:icon="@drawable/com_mixpanel_android_ic_bell"
android:title="@string/home" />
<item> </item>
.....
</group>
</menu>
主题
<style name="NavigationTheme" parent="ThemeOverlay.AppCompat.Dark">
<item name="colorControlHighlight">@color/colorAccent</item>
</style>
截图 - [R
我怎么能之间添加一个分隔符(视图)两个 menu_items
How can I add a separator (View) between two menu_items
?
推荐答案
解决方法很简单 - 单独项目分成不同的组(组必须分配的不同的,独特的ID )
Solution is simple - Separate items into different groups (groups must have assigned different, unique id's).
<menu xmlns:android="http://schemas.android.com/apk/res/android">
<group
android:id="@+id/group1"
android:checkableBehavior="single">
<item>(...)</item>
</group>
<group
android:id="@+id/group2"
android:checkableBehavior="single">
<item>(...)</item>
</group>
</menu>
修改
在您的情况,当你需要删除此填充,有两种解决方法:
In your situation, when you need to remove this padding, there are two solutions:
-
不要使用
自定义:菜单
,创建的ListView
,而不是与适配器和设置您的的ListView
并添加
Don't use
custom:menu
, createListView
instead with adapter and set for yourListView
and add
android:divider="#FFFFFF"
android:dividerHeight="1px"
该解决方案可能无法工作,因为参数可以由Android平台开发者进行更改:
This solution may not work, because parameters can be changed by Android Platform Developers:
以下行添加到 dimens.xml
<dimen name="design_navigation_padding_top_default" tools:override="true">0dp</dimen>
<dimen name="design_navigation_separator_vertical_padding" tools:override="true">0dp</dimen>
<dimen name="design_navigation_padding_bottom" tools:override="true">0dp</dimen>
或
<dimen name="navigation_separator_vertical_padding">0dp</dimen>
这篇关于如何添加分隔符菜单项?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!