Action_menu
<?xml version="1.0" encoding="utf-8" ?>
<menu xmlns:android="http://schemas.android.com/apk/res/android">
<item
android:id="@+id/menu_share"
android:icon="@drawable/ic_search_white_24dp"
android:showAsAction="ifRoom"
android:title="Search"
/>
<item
android:id="@+id/menu_settings"
android:showAsAction="never"
android:orderInCategory="100"
android:title="Setting"
/>
<group android:checkableBehavior="single">
<item android:id="@+id/selecta"
android:title="Top 50"
android:checked="true"
android:actionViewClass="android.widget.checkbox"
android:showAsAction="always"/>
<item android:id="@+id/selectb"
android:title="New & hot"
android:actionViewClass="android.widget.checkbox"
android:showAsAction="always"/>
</group>
</menu>
public override bool OnOptionsItemSelected (IMenuItem item)
{
switch (item.ItemId)
{
case Android.Resource.Id.Home:
drawerLayout.OpenDrawer (Android.Support.V4.View.GravityCompat.Start);
return true;
case Android.Resource.Id.selecta:
item.SetChecked (true);
return true;
case Android.Resource.Id.selectb:
item.SetChecked (true);
return true;
}
return base.OnOptionsItemSelected (item);
}
// Add options menu on toolbar
public override bool OnCreateOptionsMenu(Android.Views.IMenu menu)
{
MenuInflater.Inflate (Resource.Menu.Action_menu, menu);
return base.OnCreateOptionsMenu (menu);
}
我想要它们如下图
我在操作栏上添加复选框时出现问题,操作栏上没有显示复选框
答案 0 :(得分:0)
您的XML布局中存在拼写错误。对于您的复选框项目它应该是:
android:actionViewClass="android.widget.CheckBox"