0

how do I change the background of menu items in Android when they are clicked. The problem is sometimes the background is gray (as it should be) and sometimes it's blue.

Thanks in advance.

Edit: Hopefully this will clear things up. I made two screen shots. The first shows the menu on the first click. The second shows the click after I closed the menu and opened again. As you can see the item background is suddenly blue. How do I change that behavior?

Code for menu:

PopupMenu popupMenu = new PopupMenu(getContext(), view);
popupMenu.inflate(R.menu.food_context_menu);
popupMenu.setOnMenuItemClickListener(...);
popupMenu.show();

Menu layout:

<menu xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto">
    <item
        android:id="@+id/action_add_to_journal"
        android:title="@string/food_action_add_to_journal"
        app:showAsAction="withText" />
    <item
        android:id="@+id/action_edit"
        android:title="@string/food_action_edit"
        app:showAsAction="withText" />
</menu>

Style:

<resources>
    <!-- Base application theme. -->
    <style name="AppTheme" parent="Theme.AppCompat.Light.NoActionBar">
        <!-- Customize your theme here. -->
        <item name="colorPrimary">@color/primary</item>
        <item name="colorPrimaryDark">@color/primary_dark</item>
        <item name="colorAccent">@color/accent</item>
    </style>
</resources>
  • Your question is so poor. You did not add any code, the questions is not precise.. You invested 0 effort asking us. Did you mean [this](http://stackoverflow.com/questions/19659637/how-to-change-the-background-color-of-action-bars-option-menu-in-android-4-2) ? – UDKOX May 18 '16 at 11:29
  • you want it in navigation drawer? – Vishal Patoliya ツ May 18 '16 at 11:31
  • @UDKOX I think he wants to change the background color when user click on it before performing the clicked operation. – Sharad Chauhan May 18 '16 at 11:32
  • many time i got this type error and it it 99% of he is using dialog – Vishal Patoliya ツ May 18 '16 at 11:36
  • https://stackoverflow.com/questions/16036204/change-the-action-bar-settings-icon-color/16036350#16036350 – Alex Chengalan May 18 '16 at 11:52
  • I don't want to change the background of the menu. I want to change the background of the menu items when they are clicked. Per default I got the behavior that it is sometimes blue and the other time it's gray. I got that with any kind of menu: PopupMenu, OptionsMenu, NavigationView, etc. –  May 18 '16 at 12:22

0 Answers0