状态栏变色效果

设置状态栏和标题栏一致的颜色:
在应用主题中设置没有标题栏,用toolbar代码实现标题栏

<resources>

    <style name="AppTheme" parent="@style/BaseTheme">

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

</resources>

在布局中一定要设置android:fitsSystemWindows=”true”属性,这个是标题栏延伸到状态栏的效果!

<LinearLayout
    xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:orientation="vertical">

    <android.support.v7.widget.Toolbar
        android:id="@+id/toolbar"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:background="?attr/colorPrimary"
        android:fitsSystemWindows="true"
        ></android.support.v7.widget.Toolbar>

</LinearLayout>

还有的状态栏颜色要比标题栏深的效果,可以使用开源库:SystemBarTint

最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

推荐阅读更多精彩内容