[英]Checkbox on left of an item in NavigationView
I'm using the design support library's NavigationView, and in the menu it uses I have included the following: 我正在使用设计支持库的NavigationView,并且在使用的菜单中包含以下内容:
<item android:title="Check The CheckBox"
app:actionViewClass="android.support.v7.widget.AppCompatCheckBox"/>
Which solved half my problem as now I had a checkbox, however I wished to to have the CheckBox appear where usually the icon is placed, much like how it is done in the Google Calendar app with the list of calendars 现在我有了一个复选框,这解决了一半的问题,但是我希望让CheckBox出现在通常放置图标的位置,就像在带有日历列表的Google日历应用中是如何完成的
Menu items have a checkable
attribute. 菜单项具有可checkable
属性。
<item android:title="Check The CheckBox"
android:checkable="true"/>
You can also <group>
several checkable items together. 您也可以将多个可检查项一起<group>
。
<group android:checkableBehavior="all">
<item android:title="Check The CheckBox"/>
</group>
In order to have your CheckBox appear on the left of your menu items your best bet is to set the icon of your menu items as a checked or unchecked image (depending on the checked state of your menu items). 为了使CheckBox出现在菜单项的左侧,最好的选择是将菜单项的图标设置为选中或未选中的图像(取决于菜单项的选中状态)。 I've just had a look at the Google Calendar app and this is what it appears to be doing. 我刚刚看过Google日历应用,这就是它的功能。 Also, the Android Menus documentation alludes to this: 此外,Android Menus文档也暗示了这一点:
Note: Menu items in the Icon Menu (from the options menu) cannot display a checkbox or radio button. 注意:图标菜单(从选项菜单)中的菜单项无法显示复选框或单选按钮。 If you choose to make items in the Icon Menu checkable, you must manually indicate the checked state by swapping the icon and/or text each time the state changes. 如果选择使图标菜单中的项目为可检查状态,则必须在每次状态更改时通过交换图标和/或文本来手动指示已检查状态。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.