王学岗沉浸式

一句代码实现沉浸式状态栏

//设置沉浸式状态栏
private void immersiveStateBar() {
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) {
        int flagTranslucentStatus = WindowManager.LayoutParams.FLAG_TRANSLUCENT_STATUS;
        int flagTranslucentNavigation = WindowManager.LayoutParams.FLAG_TRANSLUCENT_NAVIGATION;
        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
            Window window = getWindow();
            WindowManager.LayoutParams attributes = window.getAttributes();
            attributes.flags |= flagTranslucentNavigation;
            window.setAttributes(attributes);
            getWindow().setStatusBarColor(Color.TRANSPARENT);
        } else {
            Window window = getWindow();
            WindowManager.LayoutParams attributes = window.getAttributes();
            attributes.flags |= flagTranslucentStatus | flagTranslucentNavigation;
            window.setAttributes(attributes);
        }
    }

猜你喜欢

转载自blog.csdn.net/qczg_wxg/article/details/82867892