Toolbar button gravity for extended toolbar

拥有回忆 提交于 2019-12-03 08:42:24

I played around a bit and tested a couple of combinations and can say that button's gravity and android:minHeight don't want to be friends.

This should work fine:

<android.support.v7.widget.Toolbar  xmlns:app="http://schemas.android.com/apk/res-auto" xmlns:android="http://schemas.android.com/apk/res/android"
    android:id="@+id/toolbar"
    android:layout_height="@dimen/action_bar_height"
    android:layout_width="match_parent"
    app:theme="@style/Toolbar"
    android:minHeight="?attr/actionBarSize"
    android:gravity="top"
    android:background="?attr/colorPrimary" />

If you want the icon on the top and the title on the bottom you can try something like this:

<Toolbar
    android:id="@+id/toolbar"
    android:layout_height="128dp"
    android:layout_width="match_parent"
    android:minHeight="?attr/actionBarSize"
    android:background="?attr/colorPrimary"
    android:gravity="bottom" />

Using the attribute android:minHeight as the standard actionBarSize,the buttons and actions are positioned in the top. While using the attribute android:gravity you can set the position of the title at the bottom.

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