3

I'm trying to vertical center a simple menu item on my 30dp height toolbar. I realize that Material Guidelines suggests a toolbar of 48dp, but I have too many items in my screen to give up any real estate. There must be a way of vertically centering the menu item in my toolbar??

Menu Inflation:

@Override
public boolean onCreateOptionsMenu(Menu menu) {
    super.onCreateOptionsMenu(menu);
    getMenuInflater().inflate(R.menu.menu_main, menu);
    return true;
}

Menu_main.xml:

<menu xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto">
    <item
        android:title="Function"
        android:id="@+id/menu_func_keys"
        app:showAsAction="always" />
</menu>

Here's what I'm seeing: un-centered menu item

Jay
  • 614
  • 5
  • 22

1 Answers1

11

I know it is a bit late, but if it helps...

The answer was found in this other thread: https://stackoverflow.com/a/30964331/8050896

Basically Android centers the menu items according to the minHeight parameter in your Toolbar. So set as so:

<android.support.v7.widget.Toolbar
    android:minHeight="Whatever your toolbar height is">
</android.support.v7.widget.Toolbar>

Menu items should be centered now!

P Fuster
  • 2,224
  • 1
  • 20
  • 30