In the file I activity_main_drawer.xml
define the elements of Navigation Drawer
and separate them into 3 blocks as shown in the image shown at the end of the post.
When selecting one elemento
of the first block (Start, Notices, Facilities, favourites), its background color turns gray (Correct), but if one elemento
of the second (Location, Activities, Hours) or the third block is selected (Language) does not change the background color of the element.
activity_main_drawer.xml
<?xml version="1.0" encoding="utf-8"?>
<menu xmlns:android="http://schemas.android.com/apk/res/android">
<group android:checkableBehavior="single">
<item
android:id="@+id/nav_hasiera"
android:title="@string/nav_hasiera" />
<item
android:id="@+id/nav_oharrak"
android:title="@string/nav_oharrak" />
<item
android:id="@+id/nav_instalazioak"
android:title="@string/nav_instalazioak" />
<item
android:id="@+id/nav_gustokoak"
android:title="@string/nav_gustokoak" />
</group>
<item android:title="@string/filtrar_por">
<menu>
<item
android:id="@+id/nav_lokalizazioa"
android:title="@string/nav_lokalizazio" />
<item
android:id="@+id/nav_ekintzak"
android:title="@string/nav_ekintzak" />
<item
android:id="@+id/nav_ordutegia"
android:title="@string/nav_ordutegia" />
</menu>
</item>
<item android:title="@string/opciones">
<menu>
<item
android:id="@+id/nav_hizkuntza"
android:title="@string/nav_hizkuntza" />
</menu>
</item>
</menu>
Capture after clicking on theitem
Instalaciones
The solution is to add
android:checkable="true"
to the items in the second and third groups.This is the complete code:
It is correct, with
android:checkable="true"
it you can solve this problem, I leave some references for this type of characteristics within the tag.https://developer.android.com/guide/topics/resources/menu-resource.html