Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

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);
like image 580
Alchete Avatar asked Oct 19 '14 03:10

Alchete


People also ask

What is android Studio Toolbar?

android.widget.Toolbar. A standard toolbar for use within application content. A Toolbar is a generalization of action bars for use within application layouts.


1 Answers

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

<android.support.v7.widget.Toolbar 
    android:layout_height="?attr/actionBarSize">
like image 118
Gabriele Mariotti Avatar answered Oct 01 '22 13:10

Gabriele Mariotti