1

I want to show/hide status bar outside activity.

My code is below:

activity.getWindow().getDecorView() .setSystemUiVisibility(View.SYSTEM_UI_FLAG_VISIBLE); 

It doesn't work for me. activity.getWindow() returns null.

2 Answers 2

2

Using Immersive Full-Screen Mode

HIDE / SHOW - In your Activity

// Hide status bar getWindow().addFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN); // Show status bar getWindow().clearFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN); 

More Post

Sign up to request clarification or add additional context in comments.

4 Comments

what do u mean by outside activity, where u using this ?
I dont implement native android programming. So I use activity.getWindow(); And it returns null.
I mean to say, where u actually using it may be u can get context of that activity where u can use it.
post that button function with whole java code, that can be helpful .
0
View decorView = getWindow().getDecorView(); decorView.setOnSystemUiVisibilityChangeListener (new View.OnSystemUiVisibilityChangeListener() { @Override public void onSystemUiVisibilityChange(int visibility) { // Note that system bars will only be "visible" if none of the // LOW_PROFILE, HIDE_NAVIGATION, or FULLSCREEN flags are set. if ((visibility & View.SYSTEM_UI_FLAG_FULLSCREEN) == 0) { // TODO: The system bars are visible. Make any desired // adjustments to your UI, such as showing the action bar or // other navigational controls. } else { // TODO: The system bars are NOT visible. Make any desired // adjustments to your UI, such as hiding the action bar or // other navigational controls. } } }); 

Refer this link for more details.

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

Comments