Android 显示本机菜单项之间的分隔线

Android 显示本机菜单项之间的分隔线,android,menuitem,divider,overflow-menu,Android,Menuitem,Divider,Overflow Menu,我想编辑菜单标题之间的水平线,我引用了许多解决方案,但没有一个能够找到我的解决方案。请帮助我找到解决方案 <menu xmlns:android="http://schemas.android.com/apk/res/android" xmlns:app="http://schemas.android.com/apk/res-auto"> <group android:id="@+id/grp1" android:checkableBehavior="single" >

我想编辑菜单标题之间的水平线,我引用了许多解决方案,但没有一个能够找到我的解决方案。请帮助我找到解决方案

<menu
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto">
<group android:id="@+id/grp1" android:checkableBehavior="single" >
    <item
        android:id="@+id/contact"
        android:icon="@mipmap/contact"
        android:title="Contact Us"
        android:checked="true"
        app:showAsAction="collapseActionView"/>
</group>
<group android:id="@+id/grp2" android:checkableBehavior="single" >
    <item
        android:id="@+id/latest"
        android:icon="@mipmap/latest"
        android:title="Latest ***"
        android:checked="true"
        app:showAsAction="collapseActionView"/>
</group>
<group android:id="@+id/grp3" android:checkableBehavior="single" >
<item
    android:id="@+id/my_picture"
    android:icon="@mipmap/my_picture"
    android:checked="true"
    android:title="My *** Pictures"
    app:showAsAction="collapseActionView"/>


提前感谢:)

您应该使用动作布局

<menu xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    xmlns:tools="http://schemas.android.com/tools"
    tools:context=".LandingActivity">
    <item
        android:id="@+id/action_cart"
        android:title="cart"
        android:actionLayout="@layout/cart_update_count"
        android:icon="@drawable/shape_notification"
        app:showAsAction="always"/>
</menu>

然后动作布局可以有带分隔符的文本视图

<LinearLayout
    xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="wrap_content"
    android:layout_height="match_parent"
    android:orientation="vertical">

    <View
        android:id="@+id/divider"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:background="@drawable/divider"/>

    <TextView
        android:id="@android:id/text"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:background="?android:attr/selectableItemBackground"
        android:gravity="center_vertical"          
        android:textAppearance="?attr/textAppearanceListItemSmall"/>

</LinearLayout>


然后,您可以在代码中添加单击侦听器。您应该使用操作布局

<menu xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    xmlns:tools="http://schemas.android.com/tools"
    tools:context=".LandingActivity">
    <item
        android:id="@+id/action_cart"
        android:title="cart"
        android:actionLayout="@layout/cart_update_count"
        android:icon="@drawable/shape_notification"
        app:showAsAction="always"/>
</menu>

然后动作布局可以有带分隔符的文本视图

<LinearLayout
    xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="wrap_content"
    android:layout_height="match_parent"
    android:orientation="vertical">

    <View
        android:id="@+id/divider"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:background="@drawable/divider"/>

    <TextView
        android:id="@android:id/text"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:background="?android:attr/selectableItemBackground"
        android:gravity="center_vertical"          
        android:textAppearance="?attr/textAppearanceListItemSmall"/>

</LinearLayout>


然后,您可以在代码中添加click listener,以自定义AppTheme。试试这个

<style name="AppTheme" parent="Theme.AppCompat.Light.DarkActionBar">
    <!--- Customize popmenu -->
    <item name="android:dropDownListViewStyle">@style/popup</item>
</style>

<style name="popup" parent="Widget.AppCompat.ListView.DropDown">
        <item name="android:divider">@color/colorPrimary</item>
        <item name="android:dividerHeight">1dp</item>
        <item name="android:textColor">@color/colorPrimary</item>
        <item name="android:itemBackground">@android:color/white</item>
</style>

@样式/弹出窗口
@颜色/原色
1dp
@颜色/原色
@android:彩色/白色

自定义应用主题。试试这个

<style name="AppTheme" parent="Theme.AppCompat.Light.DarkActionBar">
    <!--- Customize popmenu -->
    <item name="android:dropDownListViewStyle">@style/popup</item>
</style>

<style name="popup" parent="Widget.AppCompat.ListView.DropDown">
        <item name="android:divider">@color/colorPrimary</item>
        <item name="android:dividerHeight">1dp</item>
        <item name="android:textColor">@color/colorPrimary</item>
        <item name="android:itemBackground">@android:color/white</item>
</style>

@样式/弹出窗口
@颜色/原色
1dp
@颜色/原色
@android:彩色/白色

如果使用LinearLayout创建菜单项。如果您使用LinearLayout创建菜单项,那么只需将attr divider添加到其中。然后再加上attr分隔符。它只会在标题右侧创建一个圆,抱歉,但不起作用在不同的组中取每个项目肯定会起作用Hello hasmukh我为不同的项目取了不同的组,但结果您可以看到这可能是您的分隔器颜色必须在样式中更改,或者您的颜色为Methak hasmukh,但在样式中没有这样的东西会对此有所帮助它只是在项目的右侧创建了一个圆标题,抱歉,但不起作用在不同的组中取每个项目肯定会起作用Hello hasmukh我为不同的项目取了不同的组,但结果您可以看到这可能是您的分隔器颜色必须在样式中更改,或者Methak you hasmukh,但在样式中没有这样的东西会对此有所帮助