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.
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
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