一个Activity中多个Fragment,个别fragment实现沉浸式状态栏

如上图,同一个activity(NoActionBar)有多个fragment的情况下,只有"我的"模块需要设置为沉浸式的状态栏,而其他fragment则不需要设置。实现代码如下:

private int oldSystemUiVisibility;
private View decorView;

//初始化
decorView = getWindow().getDecorView();

//设置为透明状态栏
if (Build.VERSION.SDK_INT >= 21) {
    oldSystemUiVisibility = decorView.getSystemUiVisibility();
    int option = View.SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION
                     | View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN
                     | View.SYSTEM_UI_FLAG_LAYOUT_STABLE;
    decorView.setSystemUiVisibility(option);
    getWindow().setNavigationBarColor(Color.TRANSPARENT);
    getWindow().setStatusBarColor(Color.TRANSPARENT);
}


//取消设置透明状态栏
if (Build.VERSION.SDK_INT >= 21) {
    decorView.setSystemUiVisibility(oldSystemUiVisibility);
}

猜你喜欢

转载自blog.csdn.net/DengDongQi/article/details/84135894