Archived· · Android

Toolbar Height in Landscape mode (FIX)

Toolbar height issue

Screenshot_2015-04-19-11-32-36

If you’ve noticed by now, the Toolbar height by default when compared in normal and landscape mode, is different. There seems to be extra padding at the bottom where the Toolbar title is not vertically centered.

This issue is all the more prominent when you attach a scrollable view. The views scrolls slightly into the toolbar.

Screenshot_2015-04-19-11-32-49

The solution

Now, the fix for this is relatively simple. We need to change our toolbar height to what our minimum height is. Open toolbar.xml, remove the minHeight attribute and change the layout_height to ?attr/actionBarSize

So your initial Toolbar layout would be like this:

That would be changed to:

Here is a deliberate side by side comparison for you to see the difference between how the Toolbar height WAS in landscape, and how its supposed to be on the right (after we fixed it).

Toolbar in landscape before the fix, title not vertically centered
Toolbar in landscape after the fix, title vertically centered

So my suggestion is to stick to using the android:layout_height attribute for your Toolbar layout height and avoid using app:minHeight especially when dealing with landscape mode and scrollable views.