How to correctly display the selected items in the menu? via (with grey background):
At the moment:
Why without grey background?
My XML Menu:
<menu
xmlns:android="http://schemas.android.com/apk/res/android">
<group>
<item
android:id="@+id/night"
android:icon="@drawable/ic_brightness_3_black_24dp"
android:title="@string/navigation_view_item_1" />
<item
android:id="@+id/nearbyParkingPlaces"
android:icon="@drawable/ic_local_parking_black_24dp"
android:title="@string/navigation_view_item_2" />
<item
android:id="@+id/traffic"
android:icon="@drawable/ic_traffic_black_24dp"
android:title="@string/navigation_view_item_3" />
</group>
...
</menu>
My code for NavigationItemSelectedListener:
navigation.setNavigationItemSelectedListener { menuItem ->
drawerLayout.closeDrawers()
when (menuItem.itemId) {
R.id.night -> if (menuItem.isChecked) {
menuItem.isChecked = false
...
} else {
menuItem.isChecked = true
...
}
R.id.nearbyParkingPlaces -> if (menuItem.isChecked) {
menuItem.isChecked = false
...
} else {
menuItem.isChecked = true
...
}
R.id.traffic -> if (menuItem.isChecked) {
menuItem.isChecked = false
...
} else {
menuItem.isChecked = true
...
}
...
}
false
}
What am I doing wrong or I missed something?
If add android:checkableBehavior="all"
in <group>
- selected item have grey background, but selected elements are not combine. The previous selected item is reset... I don't understand, why and how fix it?
The solution was found