Toolbar title with custom view

可紊 提交于 2019-12-04 05:34:31

This can be solved by adding your own title (and subtitle, if you need it) text views inside the toolbar alongside your custom view.

But perhaps a better way is to use a second toolbar nested inside the first. That way, all formatting is taken care of for you.

<android.support.v7.widget.Toolbar xmlns:app="http://schemas.android.com/apk/res-auto"
    android:id="@+id/topToolbar"
    android:layout_alignParentTop="true"
    android:layout_height="wrap_content"
    android:layout_width="match_parent">

    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:orientation="horizontal">

        <android.support.v7.widget.Toolbar xmlns:app="http://schemas.android.com/apk/res-auto"
            android:id="@+id/titleToolbar"
            android:layout_width="wrap_content"
            android:layout_height="match_parent"
            app:contentInsetStart="0dp"
            app:contentInsetLeft="0dp">
        </android.support.v7.widget.Toolbar>

        <CustomView... />

    </LinearLayout>

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

If you are not using the Toolbar as an ActionBar, then maybe you could just use a layout.

I used a LinearLayout instead of a Toolbar.

What advantages is Toolbar giving you?

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