title: How to change a MenuItem icon from normal java class in Android?
body: <p>In my project, I have a class inherited from CountDownTimer, and I want to change a certain MenuItem Icon in the onFinish() method. But the code didn't work.</p>
  
  <pre><code>@Override
  public void onFinish() {
      Menu menu = newMenuInstance(context);
      MenuInflater menuInflater = new MenuInflater(context);
      menuInflater.inflate(R.menu.menu_main, menu);
      menu.findItem(R.id.menu_work).setIcon(R.mipmap.ic_action_tick);
  }
  
  protected Menu newMenuInstance(Context context) {
      try {
          Class&lt;?&gt; menuBuilderClass = Class.forName("com.android.internal.view.menu.MenuBuilder");
  
          Constructor&lt;?&gt; constructor = menuBuilderClass.getDeclaredConstructor(Context.class);
  
          return (Menu) constructor.newInstance(context);
  
      } catch (Exception e) {
          e.printStackTrace();
      }
  
      return null;
  }
  </code></pre>