Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Remove FLAG_TRANSLUCENT_STATUS at runtime

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 ?

like image 372
Mes Avatar asked Mar 23 '17 12:03

Mes


1 Answers

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))
like image 152
azizbekian Avatar answered Nov 14 '22 16:11

azizbekian