依赖库:
compile 'com.android.support:design:25.3.1'
header_layout.xml布局文件
<?xml version="1.0" encoding="utf-8"?>
<android.support.design.widget.AppBarLayout
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="wrap_content"
app:elevation="0dp"
app:theme="@style/AppTheme.AppBarOverlay">
<android.support.v7.widget.Toolbar
android:id="@+id/toolbar"
android:layout_width="match_parent"
android:layout_height="?attr/actionBarSize"
android:background="@color/colorPrimary"
app:contentInsetEnd="0dp"
app:contentInsetLeft="0dp"
app:contentInsetRight="0dp"
app:contentInsetStart="0dp"
app:navigationIcon="@null"
app:popupTheme="@style/AppTheme.PopupOverlay">
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="wrap_content">
<ImageButton
android:background="@drawable/bg_back"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:contentDescription="@null"/>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerInParent="true"
android:text="标题"/>
</RelativeLayout>
</android.support.v7.widget.Toolbar>
</android.support.design.widget.AppBarLayout>
values下的styles.xml,colors.xml
<!--styles.xml下的资源文件-->
<resources>
<!-- Base application theme. -->
<style name="BaseAppTheme" parent="Theme.AppCompat.Light.NoActionBar">
<!-- Customize your theme here. -->
<item name="colorPrimary">@color/colorPrimary</item>
<item name="colorPrimaryDark">@color/colorPrimaryDark</item>
<item name="colorAccent">@color/colorAccent</item>
</style>
<style name="AppTheme" parent="BaseAppTheme">
</style>
<style name="AppTheme.AppBarOverlay" parent="ThemeOverlay.AppCompat.Dark.ActionBar">
<item name="colorControlHighlight">@color/colorPrimary</item>
<item name="android:windowBackground">@color/colorPrimary</item>
</style>
<style name="AppTheme.PopupOverlay" parent="ThemeOverlay.AppCompat.Light">
<item name="colorControlHighlight">@color/colorPrimary</item>
<item name="android:windowBackground">@color/colorPrimary</item>
</style>
</resources>
<!--colors.xml下的资源文件-->
<?xml version="1.0" encoding="utf-8"?>
<resources>
<!--actionBar以及AppbarLayout对应颜色-->
<color name="colorPrimary">#736EB0</color>
<!--系统标题栏对应背景色-->
<color name="colorPrimaryDark">#736EB0</color>
<color name="colorAccent">#FF4081</color>
</resources>
效果图