Search code examples
androiduser-interfaceviewattributesandroid-custom-view

How to setup windowDrawsSystemBarBackgrounds programmatically?


I want to add the attribute windowDrawsSystemBarBackgrounds programmatically, or in code, instead of the values-v21, because I only need it in 1 activity, and I'm using a theme selector in my app, so I can't have multiple themes.

Is possible to enable this attribute in the code? If so, then how can I do it?

Thanks in advance.


Solution

  • I found the answer:

    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
                Window window = getWindow();
                window.clearFlags(WindowManager.LayoutParams.FLAG_TRANSLUCENT_STATUS);
                window.addFlags(WindowManager.LayoutParams.FLAG_DRAWS_SYSTEM_BAR_BACKGROUNDS);
                window.setStatusBarColor(getResources().getColor(android.R.color.transparent));
            }