Toolbar系列文章导航
之前我们说了Toolbar的各种用法,但此时我们就有小伙伴发出灵魂拷问了:太丑了,真的太丑了。哈?好吧,既然要求这么高,那么我们只能放大招了,开始自定义布局。其实很简单,就是在Toolbar的容器中加入我们自己的布局就可以了,示例代码如下:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
<androidx.appcompat.widget.Toolbar
app:contentInsetStartWithNavigation="0dp"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="@+id/tl_head">
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="wrap_content">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="中间"
android:layout_centerInParent="true"/>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="左边"/>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentRight="true"
android:text="右边"/>
</RelativeLayout>
</androidx.appcompat.widget.Toolbar>
</LinearLayout>
这样我们就在Toolbar中定义了三个文字。我们还可以定义如日期选择器等功能,或者定制我们自己的标题。也可以定义右侧的图标按钮等。