Today, when I created a left navigation bar in android app, I met a strange issue. That was I couldn’t appoint a background color for the navigation item when it was selected. Like this:

It was annoying, I found many answers on the internet, but they all couldn’t fix my issue.
Most of answers said I should created a selector in drawable folder, like:
1 | <selector xmlns:android="http://schemas.android.com/apk/res/android"> |
and set NavigationView like:
1 | app:itemBackground="@drawable/nav_view_item_background" |
For me, it is not the correct answer. Though I set the state_checked
is true and give it a drawable color, it seems the item is never checked.
For more search, I found the issue was happened with menu item.
The original menu file is:
1 |
|
Then I add a tag android:checkable=true
to it:
1 |
|
Now, the effect is normal.
