Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can I use an extended height Toolbar with menu navigation and actions centered vertically?

I'd like to have a non-standard height toolbar which has centered buttons and navigation, but I can't get it to work. I use this example layout:

<Toolbar
    android:id="@+id/toolbar_regular"
    android:background="#777"
    android:layout_width="300dp"
    android:layout_height="100dp" />

And it ends up looking like this:

Extended Height Toolbar With Uncentered Buttons

like image 432
Calvin Avatar asked Oct 21 '14 18:10

Calvin


People also ask

Which method is used to add menu to the Toolbar in Android Studio?

Make a menu xml This is going to be in res/menu/main_menu . Right click the res folder and choose New > Android Resource File. Type main_menu for the File name. Choose Menu for the Resource type.

How do I center my Toolbar title?

suggest use android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_gravity="center" instead. To keep using default styles for the customised TextView, try something like style="@style/TextAppearance. AppCompat. Widget.

What is the standard app bar Toolbar height?

The Toolbar (if not extended) has the height of: 56dp (default)


1 Answers

Per a conversation on G+ with Chris Banes, you can use minHeight to define the constrained height for actions and buttons. This value defaults to ?attr/actionBarSize on Toolbar. So, I used the layout

<Toolbar
    android:id="@+id/toolbar_regular"
    android:background="#777"
    android:minHeight="100dp"
    android:layout_width="300dp"
    android:layout_height="100dp" />

to get this appearance:

Extended Height Toolbar With Uncentered Buttons

like image 68
Calvin Avatar answered Sep 25 '22 23:09

Calvin