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

不问归期 提交于 2019-12-03 15:56:05

问题


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]

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);

回答1:


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

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


来源:https://stackoverflow.com/questions/26446870/android-support-v7-widget-toolbar-icon-alignment-issue

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!