title: Error: A factory has already been set on this LayoutInflater (change background color of menu options)
body: <p>I want to change background color of menu options. And I get <b>error</b>: <br /> <code>
  FATAL EXCEPTION: main
  java.lang.IllegalStateException: A factory has already been set on this LayoutInflater
  at android.view.LayoutInflater.setFactory(LayoutInflater.java:277) </code></p>
  
  <p>I use this <b>code</b>: <br />
  <code>
  private void setMenuBackground() { </p>
  
  <pre><code> 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; 
          } 
      }); 
  </code></pre>
  
  <p>} </p>
  
  <p></code></p>
  
  <p>I find some answers but they don't help me. <br /> How can I resolve this problem? Thanks.</p>