-1

I have used the following code to customize the background of options menu successfully.

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.blue_bg_pixel);
                    }
                });
                return view;
            }
            catch (InflateException e) {
            }
            catch (ClassNotFoundException e) {
            }
        }
        return null;
    }
});

Now I have to customize menu size, text size/color. Anybody plz help me in this.

Thanks in advance.

RivieraKid
  • 5,923
  • 4
  • 38
  • 47
Venkat Papana
  • 4,757
  • 13
  • 52
  • 74
  • Please see the answer: > http://stackoverflow.com/questions/6223846/android-adding-text-color-background-and-font-size-to-optionsmenu – Praise Song Feb 15 '13 at 12:31
  • 1
    I'm voting to close this question as off-topic because it's obsolete. Options menu was triggered by hardware menu key on platforms older than Android 4. Contemporary equivalent would be ActionBar popup menu. – Eugen Pechanec Mar 01 '19 at 20:13

2 Answers2

0

Width , Heigth you need hack action bar to that.

But if you need customize, use : ActionBarGenerator (http://jgilfelt.github.io/android-actionbarstylegenerator/)

luizfelipetx
  • 388
  • 4
  • 7
0

This fails on Android 2.3

See http://code.google.com/p/android/issues/detail?id=4441#c6 and Change menu background color on android 2.3

for details

Community
  • 1
  • 1
Marcus Wolschon
  • 2,550
  • 2
  • 22
  • 28