FLAG_TRANSLUCENT_STATUS Deprecated (FTSD)


FTSD:   SOLD       




I have a MainActivity with multiple Fragments and in one particular Fragment I want to draw behind the system bar, so I apply the following flag at runtime

    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 the user exits this Fragment and enters another one to remove that flag so that there is no content behind the status bar. I tried passing null as an argument to the setFlags() method but it gives an error. I have looked for a remove() or unSet() method but there is none. So how should I remove that flag for another Fragment?

Solution

This is an outdated way

getWindow().clearFlags(WindowManager.LayoutParams.FLAG_TRANSLUCENT_STATUS)

The latest way

Use  Window#setStatusBarColor(int) a semi-transparent color instead.

After declaring the color with the hex value #6F000000, then in the code:

getWindow().setStatusBarColor(ContextCompat.getColor(context, R.color.my_color))

Post a Comment

Previous Next

نموذج الاتصال