1

I have to change my background color of menu options to black for android 2.2 and higher, I tried it with solutions given :

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 );  

                        new Handler().post( new Runnable() {  
                            public void run () {  
                                // sets the background color   
                                view.setBackgroundResource(R.color.black);
                                // sets the text color              
                                ((TextView) view).setTextColor(Color.WHITE);
                                // sets the text size              
                                ((TextView) view).setTextSize(18);
                }
                        } );  
                    return view;
                }
            catch ( InflateException e ) {}
            catch ( ClassNotFoundException e ) {}  
       } 
        return null;
            }
    }); 
    }

But it is showing Fatal exception error "04-27 17:03:38.831: E/AndroidRuntime(923): java.lang.IllegalStateException: A factory has already been set on this LayoutInflater" . Am I doing something wrong ??

abhishek
  • 857
  • 3
  • 13
  • 34

1 Answers1

0

If I understand your question correctly. You should be able to do this in XML. Override context menu colors in Android

Community
  • 1
  • 1
EGHDK
  • 17,818
  • 45
  • 129
  • 204