Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Hide status bar in only one fragment and display it on the others

I have 3 fragments in my activity and I want to make one fragment full screen by hiding the status bar. When I exit that fragment, the status bar should reappear. How can I do that?

like image 993
Kelok Chan Avatar asked Oct 20 '22 00:10

Kelok Chan


2 Answers

Its always better to define a function in your parent activity which will have the code to hide the status bar and calling that in your target fragment will hide the status bar for that fragment and when you are exiting the fragment in its stop method you can show the status bar again.

Let this be your method in activity,

public void hideStatusBar()
    {
     // your code depending upon what you have implemented
    }

 public void showStatusBar()
        {
         // your code depending upon what you have implemented
        }

and then on fragment resume you can call this method like this,

((ParentActivity)getActivity()).hideStatusBar();

and to show it again for other fragment you can override the onStop of fragment,

((ParentActivity)getActivity()).showStatusBar();
like image 127
Ankush Sharma Avatar answered Oct 27 '22 10:10

Ankush Sharma


Visit https://developer.android.com/training/system-ui/status.html and https://developer.android.com/training/system-ui/visibility.html

clearly explained how to hide and show statusbar in different android versions.

like image 36
USKMobility Avatar answered Oct 27 '22 09:10

USKMobility