android 沉浸通知栏

IOS的沉浸式通知栏很高大上,通知栏和app统一颜色或样式,很美观。android上面也早就人实现这种效果了。android

我在这边也写一个实现通知栏沉浸式的方法,目前只实现了相同颜色。app

先要改布局文件xmlide

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:fitsSystemWindows="true"
    android:background="@color/base_red"
    android:clipToPadding="true"
    android:orientation="vertical" >
</LinearLayout>

而后在Activity的Oncreate方法里写上以下几句:布局

    @Override
    protected void onCreate(Bundle arg0) {
        super.onCreate(arg0);
        setContentView(R.layout.activity_tabmain);
        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) {// 4.4以上
            // 透明状态栏
            getWindow().addFlags(
                    WindowManager.LayoutParams.FLAG_TRANSLUCENT_STATUS);
            // 透明导航栏
            getWindow().addFlags(
                    WindowManager.LayoutParams.FLAG_TRANSLUCENT_NAVIGATION);
        }
    }

只在4.4系统以上才能用哈。ui

Fragment我没有试,直接写在父级Activity里面spa

相关文章
相关标签/搜索