How to change options menu background color in Android?

Android:How to change the background color of the options menu when selected?

  • I have created an an options menu in my application. I want to change the background color of the menu item selected. Please help me doing this.

  • Answer:

    You must try this code which will change your menu color with the menu text. private void setMenuBackground() { // TODO Auto-generated method stub getLayoutInflater().setFactory(new Factory() { @Override public View onCreateView (String name, Context context, AttributeSet attrs) { if (name.equalsIgnoreCase("com.android.internal.view.menu.IconMenuItemView")) { try { LayoutInflater f = getLayoutInflater(); final View view = f.createView(name, null, attrs); new Handler().post( new Runnable() { public void run () { view.setBackgroundColor(Color.GRAY); } }); return view; } catch (InflateException e) { } catch (ClassNotFoundException e) { } } return null; } }); }

Richa at Stack Overflow Visit the source

Was this solution helpful to you?

Related Q & A:

Just Added Q & A:

Find solution

For every problem there is a solution! Proved by Solucija.

  • Got an issue and looking for advice?

  • Ask Solucija to search every corner of the Web for help.

  • Get workable solutions and helpful tips in a moment.

Just ask Solucija about an issue you face and immediately get a list of ready solutions, answers and tips from other Internet users. We always provide the most suitable and complete answer to your question at the top, along with a few good alternatives below.