I'm trying to add a switch as menuitem in NavigationView like this
I used the the actionViewClass attribute but it only shows the title.
<item
android:id="@+id/navi_item_create_notifications_sound"
android:title="Notifications Sounds"
xmlns:app="http://schemas.android.com/apk/res-auto"
app:actionViewClass="android.support.v7.widget.SwitchCompat"
app:showAsAction="always" />
The new support library 23.1
allows using a custom view for the items in Navigation View using
app:actionLayout
or usingMenuItemCompat.setActionView()
.Here's how I managed to display a SwitchCompat
menu_nav.xml
menu_switch.xml
To get the View and assign events to it, you should do :