android – 在ActionBar中的菜单项上添加复选框

android – 在ActionBar中的菜单项上添加复选框,第1张

概述我的 *** 作栏中有问题.我正在尝试在ActionBar中的菜单项添加一个复选框,但它不起作用.它只显示复选框的标题. 这是我的menu.xml: <menu xmlns:android="http://schemas.android.com/apk/res/android" xmlns:app="http://schemas.android.com/apk/res-auto" xml 我的 *** 作栏中有问题.我正在尝试在Actionbar中的菜单项上添加一个复选框,但它不起作用.它只显示复选框的标题.

@H_301_8@

这是我的menu.xml:@H_301_8@

@H_301_8@

<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="com.tracking.bus.maps.SingleVIEwMapsActivity" >        <item        androID:ID="@+ID/actionbar_alarm"        androID:title="@string/actionbar_alarm"        app:actionVIEwClass="androID.Widget.checkBox"        app:showAsAction="ifRoom"/></menu>
解决方法
<?xml version="1.0" enCoding="utf-8"?><menu xmlns:androID="http://schemas.androID.com/apk/res/androID">    <!-- Checkable items appear only in submenus or context menus. -->    <!-- Carefully look at the attribute name checkableBehavior on groups,but         the attribute name checkable on items. The checkableBehavior encompasses         the number of items that will be checkable within that group. -->    <item androID:title="None">        <menu>            <!-- The none checkableBehavior is default,but we explicitly show it here. -->            <group                androID:ID="@+ID/noncheckable_group"                androID:checkableBehavior="none">                <!-- Notice how these items inherit from the group. -->                <item                    androID:ID="@+ID/noncheckable_item_1"                    androID:title="@string/item_1" />                <item                    androID:ID="@+ID/noncheckable_item_2"                    androID:title="@string/item_2" />                <item                    androID:ID="@+ID/noncheckable_item_3"                    androID:title="@string/item_3" />            </group>        </menu>    </item>    <item androID:title="All">        <menu>            <group                androID:ID="@+ID/checkable_group"                androID:checkableBehavior="all">                <!-- Notice how these items inherit from the group. -->                <item                    androID:ID="@+ID/checkable_item_1"                    androID:title="@string/item_1" />                <item                    androID:ID="@+ID/checkable_item_2"                    androID:checked="true"                    androID:title="@string/item_2" />                <item                    androID:ID="@+ID/checkable_item_3"                    androID:checked="true"                    androID:title="@string/item_3" />            </group>        </menu>    </item>    <item androID:title="Single">        <menu>            <group                androID:ID="@+ID/exclusive_checkable_group"                androID:checkableBehavior="single">                <!-- Notice how these items inherit from the group. -->                <item                    androID:ID="@+ID/exclusive_checkable_item_1"                    androID:title="@string/item_1" />                <item                    androID:ID="@+ID/exclusive_checkable_item_2"                    androID:title="@string/item_2" />                <item                    androID:ID="@+ID/exclusive_checkable_item_3"                    androID:checked="true"                    androID:title="@string/item_3" />            </group>        </menu>    </item>    <item androID:title="All without group">        <menu>            <!-- Notice how these items have each set. -->            <item                androID:ID="@+ID/nongroup_checkable_item_1"                androID:checkable="true"                androID:title="@string/item_1" />            <item                androID:ID="@+ID/nongroup_checkable_item_2"                androID:checkable="true"                androID:checked="true"                androID:title="@string/item_2" />            <item                androID:ID="@+ID/nongroup_checkable_item_3"                androID:checkable="true"                androID:checked="true"                androID:title="@string/item_3" />        </menu>    </item></menu>
总结

以上是内存溢出为你收集整理的android – 在ActionBar中的菜单项上添加复选框全部内容,希望文章能够帮你解决android – 在ActionBar中的菜单项上添加复选框所遇到的程序开发问题。

如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。

欢迎分享,转载请注明来源:内存溢出

原文地址: https://outofmemory.cn/web/1130093.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2022-05-30
下一篇 2022-05-30

发表评论

登录后才能评论

评论列表(0条)

保存