5

I have two fragments in my activity, fA and fB. When I click a button in fA, fB replaces fA. fB is just like the google play store view, when you open to view some app. The image is under a transparent status bar. I did this by adding this code to fB#onCreateView:

    Window w = getActivity().getWindow();
    w.getDecorView().setSystemUiVisibility(
            View.SYSTEM_UI_FLAG_LAYOUT_STABLE
                    | View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN);
    w.setStatusBarColor(Color.TRANSPARENT);

When I press back, fB is removed and is replace by fA, everything's normal, but the toolbar is under the status bar. Like:

enter image description here

whereas, it should look like: enter image description here

This is what it looks like when the fragment is first loaded.

Is there any way to clear the flags I set in fB? I've tried to put this code in the onResume of the fragment but no luck!

    w.getDecorView().setSystemUiVisibility(
            View.SYSTEM_UI_FLAG_LAYOUT_STABLE
                    |View.SYSTEM_UI_FLAG_VISIBLE);

and, i've also tried:

    w.clearFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN);
    w.addFlags(WindowManager.LayoutParams.FLAG_FORCE_NOT_FULLSCREEN);

Any other way to fix this? Thank You!

hello_world
  • 778
  • 1
  • 10
  • 26

1 Answers1

3

I guess it's a bit late to answer this question. Write these lines of codes in the onDestroy method of your fragment:

To show the status bar:

requireActivity().window.clearFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN)

To show Navigation bar:

getWindow().getDecorView().setSystemUiVisibility(View.SYSTEM_UI_FLAG_VISIBLE);
Pouya Heydari
  • 2,496
  • 26
  • 39