android 沉浸通知栏

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

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

先要改布局文件xml

<?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系统以上才能用哈。

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

posted @ 2015-12-29 15:35  池塘里的大象  阅读(939)  评论(0编辑  收藏  举报