how to get white background theme for android options menu?

4.2k Views Asked by At

In my android application I would like my options menu to have a white background so that my icons show up better, I have seen many apps that had this but I am unable to figure out how to get this done.

2

There are 2 best solutions below

1
On

The answers int his link will probably help you. This site gives you answer in many ways, for example using android:state_pressed=true and other options too(selected, focused) in your menu item will show your background of your item in white color.

How to change the background color of the options menu?

0
On

I'm not a fan of the standard options menu at all that's why I ALWAYS create a customized menu with ViewStubs. Just create a new layout where you design your menu bar, integrate it with ViewStub in your layout files and let the menu slide in.

Sample java code:

public boolean onKeyDown( int keyCode, KeyEvent event ) {
    switch (keyCode) {
        case KeyEvent.KEYCODE_MENU:
            mMenuPanel = ( ( ViewStub ) findViewById( R.id.stub_onoption ) ).inflate();
            // initialize buttons of your menu layout and define setOnClickListener()
            if( !menuVisible ) {
                constants.showPanel( this, mMenuPanel, true );
                menuVisible = true;
            } else {
                constants.hidePanel( this, mMenuPanel, true );
                menuVisible = false;
            }
            return true;
    default:
        break;
    }
}

public static void hidePanel( Context context, View panel, boolean slideDown ) {
    panel.startAnimation( AnimationUtils.loadAnimation( context, slideDown ? R.anim.slide_out : R.anim.slide_in_top ) );
    panel.setVisibility( View.GONE );
}

public static void showPanel( Context context, View panel, boolean slideUp ) {
    panel.startAnimation( AnimationUtils.loadAnimation( context, slideUp ? R.anim.slide_in : R.anim.slide_out_top ) );
    panel.setVisibility( View.VISIBLE );
}

This way you'll be able to fully customize your menu bar (background buttons etc.)

Edit: This is just the rough idea how to do it. And if you're doing it for the first time it might be a little bit overweight just for changing the background color but You'll be able to use this concept later on in various occasions like different slide in effects, adjusting the menu design according to your application design, change location, size and many more things. Furthermore this kind of concept can also be used for optional search bars, or in-app notifications (if you don't want to use a dialog). So it's definitely worth looking into it.