Home > database >  How to set the colors of an Options Menu
How to set the colors of an Options Menu

Time:12-06

I have an older app that uses openOptionsMenu() and onCreateOptionsMenu() to bring up a menu. Yes, I know this is obsolete, and replacing it with a more modern UI is on my short list of things to do, but I have a problem I'm hoping to solve today.

Basically, if the entire menu doesn't fit on the screen, there is a "More" item at the end that opens a popup when you select it. It worked perfectly on older versions of Android, but now it looks like this:

Android bad options menu

Any time I try to look up "options menu colors" or "options menu theme", the search results always lead me to ActionBar or Toolbar. But my app doesn't use either of these.

Any hints as to how I control the appearance of an old options menu?


Relevant source code:

@TargetApi(Build.VERSION_CODES.ICE_CREAM_SANDWICH)
@Override
public boolean onCreateOptionsMenu(Menu menu) {
    super.onCreateOptionsMenu(menu);
    menu.add(0, MENU_ABOUT, 0, R.string.About)
      .setAlphabeticShortcut('a')
      .setIcon(android.R.drawable.ic_menu_info_details);
    menu.add(0, MENU_BASIC, 0, R.string.Basic)
      .setAlphabeticShortcut('b')
      .setIcon(R.drawable.calc);
    menu.add(0, MENU_SCI, 0, R.string.Scientific)
      .setAlphabeticShortcut('s')
      .setIcon(R.drawable.science);
    menu.add(0, MENU_TAPE, 0, R.string.Tape)
      .setAlphabeticShortcut('t')
      .setIcon(R.drawable.tape);
    menu.add(0, MENU_HELP, 0, R.string.Help)
      .setAlphabeticShortcut('h')
      .setIcon(android.R.drawable.ic_menu_help);
    menu.add(0, MENU_PREFERENCES, 0, R.string.Preferences)
      .setAlphabeticShortcut('p')
      .setIcon(android.R.drawable.ic_menu_preferences);

    return true;
}

CodePudding user response:

Specy the background color and text color in styles. ie

res -> values -> styles.xml file.

<style name="AppTheme" parent="Theme.AppCompat.Light.NoActionBar">
<item name="android:itemBackground">#ffffff</item>
<item name="android:textColor">#000000</item>
  • Related