Transparent status bar - before Android 4.4 (KitKat)

前端 未结 2 579
梦毁少年i
梦毁少年i 2020-12-04 16:16

I know in Android 4.4 KitKat (API 19) it\'s possible to make the status bar transparent.

But for example, Go Launcher Ex and others have an option to make it transpa

2条回答
  •  遥遥无期
    2020-12-04 16:33

    Use this. :)

    after super() and before set content.

    if (Build.VERSION.SDK_INT >= 19)
    {
        getWindow().getDecorView().setSystemUiVisibility(View.SYSTEM_UI_FLAG_LAYOUT_STABLE | View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN);
    }
    
    if (Build.VERSION.SDK_INT >= 19 && Build.VERSION.SDK_INT < 21)
    {
        setWindowFlag(this, WindowManager.LayoutParams.FLAG_TRANSLUCENT_STATUS, true);
    }
    
    if (Build.VERSION.SDK_INT >= 21)
    {
        setWindowFlag(this, WindowManager.LayoutParams.FLAG_TRANSLUCENT_STATUS, false);
        getWindow().setStatusBarColor(Color.TRANSPARENT);
    }
    
    
    public static void setWindowFlag(Activity activity, final int bits, boolean state)
    {
        Window win = activity.getWindow();
        WindowManager.LayoutParams winParams = win.getAttributes();
    
        if (state)
         {
            winParams.flags |= bits;
        }
         else
         {
            winParams.flags &= ~bits;
        }
    }
    

提交回复
热议问题