美文网首页
简单实现沉浸式状态栏

简单实现沉浸式状态栏

作者: duwensheng | 来源:发表于2018-07-27 08:03 被阅读0次

在Activity中加入以下代码:

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);

    }

}

相关文章

网友评论

      本文标题:简单实现沉浸式状态栏

      本文链接:https://www.haomeiwen.com/subject/muqwmftx.html