17

Im having problems with the new way to use toolbar. In landscape mode, toolbar title is centered vertically but the navigation drawer not. How can I solve this?

I am using the toolbar like in this post of Chris Banes: AppCompat v21 — Material Design for Pre-Lollipop Devices!

This is the code for the drawer icon in style.xml:

<style name="DrawerArrowStyle" parent="Widget.AppCompat.DrawerArrowToggle">
    <item name="spinBars">true</item>
    <item name="color">@android:color/white</item>
</style>

And this is an image of the problem: Landscape image

EDIT: Overflow button is not centered vertically too...

JavierSegoviaCordoba
  • 6,531
  • 9
  • 37
  • 51

2 Answers2

29

This is my toolbar theme and everything is centered correctly:

<android.support.v7.widget.Toolbar
    android:layout_width="match_parent"
    android:layout_height="?actionBarSize"
    style="@style/Widget.MyApp.Toolbar">

</android.support.v7.widget.Toolbar>

The example says to use android:minHeight="?actionBarSize" and android:_layout_height="wrap_content" but it only produced the error you described.

Eugen Pechanec
  • 37,669
  • 7
  • 103
  • 124
  • In my case, this nicely centered everything, but for some reason it changes the height of the toolbar as the device is rotated (it's shorter in landscape for some reason). So visually, this is a workable solution. – GaryAmundson Jan 31 '15 at 16:05
  • Yes, the specs say that the action bar is always 56dp on phones. But the specs lie. It's actually implemented as 48dp in landscape. This is by design and correct, in the end the space is limited. – Eugen Pechanec Jan 31 '15 at 16:08
  • 1
    Implemented this and initially didn't get it to work. Then realized the toolbar was in a layout being included elsewhere where the layout_height was overriding ?actionBarSize. Thanks! – Vic Alcazar Feb 02 '15 at 15:16
  • 1
    this cuts off toolbar subtitles though – behelit Feb 23 '17 at 22:20
6

Add this in your toolbar style:

<item name="maxButtonHeight">?attr/actionBarSize</item>

This allows you to use wrap_content height and still have a centered icon!

Tytanium
  • 101
  • 1
  • 7
  • This is a better solution, it doesn't cut the toolbar subtitle. Can also be done in xml `app:maxButtonHeight="?attr/actionBarSize"` – behelit Feb 23 '17 at 22:22