android.support.v7.widget.Toolbar icon alignment issue

Alchete picture Alchete · Oct 19, 2014 · Viewed 12k times · Source

Using the new Android 5.0 Toolbar approach, and following the Google IO example, I'm setting a navigation icon and a spinner in the toolbar.

The issue is, the navigation icon is BOTTOM-aligned. I can't find any reason why this is happening...

[Note that I deliberately set it to a solid square to see the alignment issue more clearly]

enter image description here

My code is as follows:

toolbar.xml

<android.support.v7.widget.Toolbar 
    xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    app:theme="@style/ActionBarThemeOverlay"
    app:popupTheme="@style/ActionBarPopupThemeOverlay"
    android:id="@+id/toolbar_actionbar"
    android:layout_width="match_parent"
    android:layout_height="?android:actionBarSize"
    />

Main Style

<style name="ActionBarThemeOverlay" parent="">
    <item name="android:background">@color/appMainColor</item>
    <item name="android:textColorPrimary">#fff</item>
    <item name="colorControlNormal">#ffff</item>
    <item name="colorControlHighlight">#3fff</item>
</style>

ActivityMain

getSupportActionBar().setDisplayHomeAsUpEnabled(true);

if (mActionBarToolbar != null)
    mActionBarToolbar.setNavigationIcon(R.drawable.ic_drawer);

Answer

Gabriele Mariotti picture Gabriele Mariotti · Oct 19, 2014

Try to use ?attr/actionBarSize instead of android:layout_height="?android:actionBarSize"

<android.support.v7.widget.Toolbar 
    android:layout_height="?attr/actionBarSize">