简体   繁体   中英

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:

<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

Menu items have a checkable attribute.

<item android:title="Check The CheckBox"
    android:checkable="true"/>

You can also <group> several checkable items together.

<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). I've just had a look at the Google Calendar app and this is what it appears to be doing. Also, the Android Menus documentation alludes to this:

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM