首页 > 代码库 > Toolbar实现透明状态栏

Toolbar实现透明状态栏

主题样式兼容:

values:

 <style name="BaseTheme"  parent="Theme.AppCompat.Light.NoActionBar"/>
    <style name="AppTheme" parent="BaseTheme">
        <item name="colorPrimary">@color/colorPrimary</item>
        <item name="colorPrimaryDark">@color/colorPrimaryDark</item>
        <item name="colorAccent">@color/colorAccent</item>
    </style>

values-v19:

<style name="BaseTheme" parent="Theme.AppCompat.Light.NoActionBar"/>

    <style name="AppTheme" parent="BaseTheme">
        <item name="android:windowTranslucentStatus">true</item>
        <item name="colorPrimary">@color/colorPrimary</item>
        <item name="colorPrimaryDark">@color/colorPrimaryDark</item>
        <item name="colorAccent">@color/colorAccent</item>
    </style>

values-v21:
 <style name="AppTheme" parent="BaseTheme">
        <item name="android:colorPrimary">@color/colorPrimary</item>
        <item name="android:colorPrimaryDark">@color/colorPrimary</item>
        <item name="android:colorAccent">@color/colorAccent</item>
    </style>
设置pading大小
 values-21
<dimen name="toolbar_padding_top">0dp</dimen>
 values-19
<dimen name="toolbar_padding_top">25dp</dimen>
 values
<dimen name="toolbar_padding_top">0dp</dimen>


布局代码:
<?xml version="1.0" encoding="utf-8"?>
<android.support.v7.widget.Toolbar
        xmlns:android="http://schemas.android.com/apk/res/android"
        xmlns:app="http://schemas.android.com/apk/res-auto"
        android:id="@+id/tb_toolbar"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:background="@color/colorPrimary"
        app:popupTheme="@style/ThemeOverlay.AppCompat.Light"
        android:paddingTop="@dimen/toolbar_padding_top"
        app:contentInsetStart="0dp"     // 去掉toolbar左边默认编剧
        app:titleTextColor="@android:color/white">

   //自定义布局高度
    <RelativeLayout android:layout_width="match_parent"
                    android:layout_height="48dp"
    >
        <TextView android:layout_width="match_parent"
                  android:layout_height="wrap_content"
                  android:gravity="center"
                  android:text="标题栏"
                  android:layout_centerInParent="true"
                  android:textColor="@android:color/white"
        />

    </RelativeLayout>

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

        <!--android:minHeight="?actionBarSize"-->

 








 

Toolbar实现透明状态栏