title: How to center action menu on toolbar
body: <p>I have an application with a <a href="http://developer.android.com/guide/topics/ui/actionbar.html#SplitBar" rel="nofollow noreferrer">split action bar</a> loading an action menu.</p>
  
  <p>I changed the actionbar for the new toolbar and replaced the split actionbar by an other toolbar used in standalone mode : </p>
  
  <pre><code>Toolbar toolbarBottom = (Toolbar) findViewById(R.id.toolbarBottom);
  toolbarBottom.inflateMenu(R.menu.ab_one_cam);
  </code></pre>
  
  <p>As specified in the documentation the action menu is pin to the right of the toolbar :
  <img src="https://i.stack.imgur.com/k2woW.png" alt="enter image description here"></p>
  
  <p>But i would like the icons to be centered on the toolbar , like it was on the split actionbar :
  <img src="https://i.stack.imgur.com/MdA6Q.png" alt="enter image description here"></p>
  
  <p><strong>How can i make the action menu take all the available space on the toolbar ?</strong></p>
  
  <p>The toolbar is dedicated to this menu , nothing else will be added on it.</p>
  
  <p><strong>Answer</strong>  </p>
  
  <p>The accepted answer's link lead to a split toolbar. If like me you have very simple need this code is good enough : </p>
  
  <pre><code>public class SplitToolbar extends Toolbar {
  
      public SplitToolbar(Context context) {
          super(context);
      }
  
      public SplitToolbar(Context context, AttributeSet attrs) {
          super(context, attrs);
      }
  
      public SplitToolbar(Context context, AttributeSet attrs, int defStyleAttr) {
          super(context, attrs, defStyleAttr);
      }
  
      @Override
      public void addView(View child, ViewGroup.LayoutParams params) {
          if (child instanceof ActionMenuView) {
              params.width = LayoutParams.MATCH_PARENT;
          }
          super.addView(child, params);
      }
  }
  </code></pre>
  
  <p>Credit goes to : <a href="https://gist.github.com/dodgex/7bc81fd2cbb70a8d5117" rel="nofollow noreferrer">https://gist.github.com/dodgex/7bc81fd2cbb70a8d5117</a></p>