toolBar和默认的手机标题栏处理

依赖库:

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>

效果图
效果图片

  • 1
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 1
    评论
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值