Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>A solution is provided <a href="http://www.techjini.com/blog/2011/04/19/customizing-background-and-text-color-in-options-menu-android/" rel="nofollow">here</a> . But it does not seem to be a great way to do it. </p> <p>Try the following: </p> <pre><code>@Override public boolean onCreateOptionsMenu(Menu menu) { // TODO :create the menu MenuInflater inflator = getMenuInflater(); inflator.inflate(R.menu.home_screen_menu, menu); setMenuBackground(); return true; } </code></pre> <p>The following will just change the background : </p> <pre><code>protected void setMenuBackground() { // Log.d(TAG, "Enterting setMenuBackGround"); getLayoutInflater().setFactory(new Factory() { @Override 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.menu_bg); } }); return view; } catch (InflateException e) { } catch (ClassNotFoundException e) { } } return null; } }); } </code></pre> <p>I define menu_bg in drawable folder as :</p> <pre><code>&lt;xml version="1.0" encoding="UTF-8"?&gt; &lt;shape xmlns:android="http://schemas.android.com/apk/res/android" android:shape="rectangle"&gt; &lt;gradient android:startColor="#AA000000" android:endColor="#AA000000" android:angle="90"/&gt; &lt;/shape&gt; </code></pre> <p>to google android developers : please provide an easier way to do this!.</p>
 

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