How to set Android toolbar height?

我们两清 提交于 2019-12-05 01:27:16
<android.support.v7.widget.Toolbar xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/toolbarTitle"
android:orientation="vertical"
android:background="@color/black"
android:layout_width="match_parent"
android:fitsSystemWindows="true"
android:minHeight="?attr/actionBarSize" //pay attention here
android:theme="@style/AppTheme"
android:layout_height="wrap_content"> //pay attention here

your ToolBar which is a ViewGroup is wraping its height around its children meaning it will get a fixed size only if the children are measured. your minimum height is around 50 to 60 dip, that is how low your ToolBar will be. so if your children height do not add up to a reasonable big number it will still be <= 50

give it a prefered height android:layout_height="200dp"

Use some theme with no action bar for this activity or the whole app if you don't need action bar's functionality (like Theme.Holo.NoActionBar). You can add layout of your top bar directly in activities root layout. If you will use it in other activities then consider making separate xml files for layout or even your own ActionBarView class.

you can use AppBarLayout like this :


<android.support.design.widget.AppBarLayout
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:theme="@style/AppTheme">

        <android.support.v7.widget.Toolbar
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:id="@+id/toolbar_"
            app:layout_scrollFlags="scroll|enterAlways"
            app:popupTheme="@style/AppTheme.PopupOverlay">

        </android.support.v7.widget.Toolbar>

        <android.support.design.widget.TabLayout
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:id="@+id/tabs"
            app:tabBackground="@color/White"
            app:tabIndicatorColor="@color/OrangeFFC200"
            app:tabTextAppearance="@style/MineCustomTabText">

        </android.support.design.widget.TabLayout>

</android.support.design.widget.AppBarLayout>

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