通知栏,状态栏的隐藏与各种细节(坑)

5.0以上通知栏透明

getWindow().requestFeature(Window.FEATURE_NO_TITLE);
        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
            Window window = getWindow();
            window.clearFlags(WindowManager.LayoutParams.FLAG_TRANSLUCENT_STATUS
                    | WindowManager.LayoutParams.FLAG_TRANSLUCENT_NAVIGATION);
            window.getDecorView().setSystemUiVisibility(View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN
                    | View.SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION
                    | View.SYSTEM_UI_FLAG_LAYOUT_STABLE);
            window.addFlags(WindowManager.LayoutParams.FLAG_DRAWS_SYSTEM_BAR_BACKGROUNDS);
            window.setStatusBarColor(Color.TRANSPARENT);
            window.setNavigationBarColor(Color.TRANSPARENT);
        }

全屏(状态栏,通知栏全消失)

        //隐藏标题栏
        requestWindowFeature(Window.FEATURE_NO_TITLE);
        //隐藏状态栏
getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN,WindowManager.LayoutParams.FLAG_FULLSCREEN); 

或者设置主题为(NoTitleBar–去掉标题栏;Fullscreen–去掉状态栏):

android:theme="@android:style/Theme.Light.NoTitleBar.Fullscreen"

注意:

requestWindowFeature(Window.FEATURE_NO_TITLE);

无效解决办法:
1.使用supportRequestWindowFeature(Window.FEATURE_NO_TITLE);
2. 当activity继承AppCompatActivity,可修改主题为: