Remove FLAG_TRANSLUCENT_STATUS at runtime
Asked Answered
P

1

6

I have a MainActivity with lots of Fragments and in one specific Fragment I want to draw behind system bar, so I'm applying at runtime the following flag :

    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
        getActivity().getWindow().setFlags(WindowManager.LayoutParams.FLAG_TRANSLUCENT_STATUS, WindowManager.LayoutParams.FLAG_TRANSLUCENT_STATUS);
    }

What I want now is when user exits this Fragment and enters another to remove that flag so there's no content behind status bar. I tried passing null as arguments to setFlags() method but that's giving an error. I have searched for remove() or unSet() methods but none exists. So how should I remove that flag for another Fragment ?

Performance answered 23/3, 2017 at 12:23 Comment(0)
S
11
getWindow().clearFlags(WindowManager.LayoutParams.FLAG_TRANSLUCENT_STATUS)

FLAG_TRANSLUCENT_STATUS got deprecated with following suggestion:

Use Window#setStatusBarColor(int) with a half-translucent color instead.

Having declared a color with hex value #6F000000, then in code:

getWindow().setStatusBarColor(ContextCompat.getColor(context, R.color.my_color))
Startle answered 23/3, 2017 at 12:42 Comment(2)
FLAG_TRANSLUCENT_STATUS code is deprecated, do you have any updated answerWaxy
FLAG_TRANSLUCENT_STATUS code is deprecated, am also looking for sameGypsie

© 2022 - 2024 — McMap. All rights reserved.