自定义Toolbar,实现方式如下:

1.布局文件,在activity_main.xml 文件中写入Toolbar
<?xml version="1.0" encoding="utf-8"?> <android.support.constraint.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android" xmlns:tools="http://schemas.android.com/tools" android:layout_width="match_parent" android:layout_height="match_parent" xmlns:app="http://schemas.android.com/apk/res-auto"> <android.support.v7.widget.Toolbar android:id="@+id/main_toolbar" android:layout_width="match_parent" android:layout_height="wrap_content" android:minHeight="?attr/actionBarSize" android:background="@color/colorblue" app:contentInsetStart="0dp" android:layout_gravity="center" app:popupTheme="@style/AppTheme.PopupOverlay"> <TextView android:layout_width="match_parent" android:layout_height="wrap_content" android:gravity="center" android:text="标题" android:textColor="@color/group_button_dialog_pressed_holo_light" android:textSize="22sp" /> </android.support.v7.widget.Toolbar> .......