Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>I am using the following. Put this method in your activity and call it in the onCreateOptionsMenu(Menu menu) method. You can instead of setting the backgroundResource just set a color... just type view.setbackground and see the possibilities via autocompletion ;)</p> <pre><code>/* * IconMenuItemView is the class that creates and controls the options menu * which is derived from basic View class. So We can use a LayoutInflater * object to create a view and apply the background. */ protected void setMenuBackground() { Log.d(TAG, "Enterting setMenuBackGround"); getLayoutInflater().setFactory(new Factory() { public View onCreateView(String name, Context context, AttributeSet attrs) { if (name .equalsIgnoreCase("com.android.internal.view.menu.IconMenuItemView")) { try { // Ask our inflater to create the view LayoutInflater f = getLayoutInflater(); final View view = f.createView(name, null, attrs); /* * The background gets refreshed each time a new item is * added the options menu. So each time Android applies * the default background we need to set our own * background. This is done using a thread giving the * background change as runnable object */ new Handler().post(new Runnable() { public void run() { view .setBackgroundResource(R.drawable.row_blue_menu); } }); return view; } catch (InflateException e) { } catch (ClassNotFoundException e) { } } return null; } }); } </code></pre> <p>. </p> <pre><code> @Override public boolean onCreateOptionsMenu(Menu menu) { super.onCreateOptionsMenu(menu); getMenuInflater().inflate(R.menu.start_menue, menu); setMenuBackground(); return true; } </code></pre>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload