I have used the method presented here to hide Navigationbar. It works properly but when I tap the context menu button (three vertical points in the right side of the toolbar), the navigationbar is appeared again.
I have used the code:
View decorView = getWindow().getDecorView();
decorView.setSystemUiVisibility(View.SYSTEM_UI_FLAG_LAYOUT_STABLE
| View.SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION
| View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN
| View.SYSTEM_UI_FLAG_HIDE_NAVIGATION
| View.SYSTEM_UI_FLAG_FULLSCREEN
| View.SYSTEM_UI_FLAG_IMMERSIVE_STICKY);
in onResume(), onCreate(), onOptionsItemSelected(), onWindowFocusChanged().
If all of menu items are set to app:showAsAction="always" the Navigationbar is never appeared but when some are shown in the list, it appeard.
Related
mContext.getWindow().getDecorView().setSystemUiVisibility(
View.SYSTEM_UI_FLAG_LAYOUT_STABLE
| View.SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION
| View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN
| View.SYSTEM_UI_FLAG_HIDE_NAVIGATION
| View.SYSTEM_UI_FLAG_FULLSCREEN
| View.SYSTEM_UI_FLAG_IMMERSIVE_STICKY
I am using the above codes to hide enter the full screen mode. It can be exited by swiping back, top or bottom. However, the Action Bar remains hidden, while the status bar and navigation bar appears (Picture 2).
How can I bring up the ActionBar ? Or detecting the "Exit" (Picture 3) event listener so that I can call the following to show ActionBar?
mContext.getWindow().getDecorView().setSystemUiVisibility(
View.SYSTEM_UI_FLAG_LAYOUT_STABLE
| View.SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION
| View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN
);
Due to design requirement, I can't use the touch listener to bring up the ActionBar() in this case.
I want to hide navigation bar. Onyl show it if the user drugs his finger from outside to inside.
I test this code:
#Override
public void onWindowFocusChanged(boolean hasFocus) {
super.onWindowFocusChanged(hasFocus);
if(hasFocus) {
getWindow().getDecorView().setSystemUiVisibility(View.SYSTEM_UI_FLAG_LAYOUT_STABLE
| View.SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION
| View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN
| View.SYSTEM_UI_FLAG_HIDE_NAVIGATION
| View.SYSTEM_UI_FLAG_FULLSCREEN
| View.SYSTEM_UI_FLAG_IMMERSIVE);
}
}
The activity starts well and the navigation bars not appear. Buti have the next problems:
1) If a touch the screen anywhere the navigation bar is show.
2) When it's show, its not showing transparent.
3) Navigation bar never hides.
How can add this three items? What I'm missing.
Add the sticky flag View.SYSTEM_UI_FLAG_IMMERSIVE_STICKY to setSystemUiVisibility as described in the documentation https://developer.android.com/training/system-ui/immersive.html#sticky
That way after swiping from the screen edge, navigation bars will show for some seconds and then hide again.
I'm implementing immersive mode using this code:
activity.getWindow().getDecorView().setSystemUiVisibility(
View.SYSTEM_UI_FLAG_LAYOUT_STABLE
| View.SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION
| View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN
| View.SYSTEM_UI_FLAG_HIDE_NAVIGATION
| View.SYSTEM_UI_FLAG_FULLSCREEN
| View.SYSTEM_UI_FLAG_IMMERSIVE
);
But the problem is as I scroll the recycler view, the status and navigation bar are shown as an item view reaches the top. It's hard to explain but here's the gif:
https://giphy.com/gifs/xT4uQiBlagrD9ljQqc
Note that as an item view approaches the top, the status bar is shown (only the dark background is shown though). Note also the navigation bar as an item view's bottom reaches the boundary of the navigation bar (notice the gray background at the bottom).
This happens for every item in the recycler view which is really annoying.
It's missing you some UI options like immersive sticky.
Here's my working ui options:
View decorView = getWindow().getDecorView();
int uiOptions = View.SYSTEM_UI_FLAG_LAYOUT_STABLE
| View.SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION
| View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN
| View.SYSTEM_UI_FLAG_HIDE_NAVIGATION
| View.SYSTEM_UI_FLAG_FULLSCREEN
| View.SYSTEM_UI_FLAG_IMMERSIVE_STICKY;
decorView.setSystemUiVisibility(uiOptions);
I am trying to expand a VideoView to full screen and horizontal mode whenever a 'full-screen' button is clicked, but I cannot find a way to expand the view completely over the whole screen. I have a toolbar and a tabbed layout I can't find a way to bypass both of them and apply the view over them. Anybody has ideas how I can achieve this?
Without code I am not sure of your layout but, translate your TabLayout out of the way and go to 'immersive' mode to hide all system bars. You can use the following method:
private void hideSystemUI() {
// Set the content to appear under the system bars so that the content
// doesn't resize when the system bars hide and show.
getWindow().getDecorView().setFitsSystemWindows(false);
getWindow().getDecorView().setSystemUiVisibility(
View.SYSTEM_UI_FLAG_LAYOUT_STABLE
| View.SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION
| View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN
| View.SYSTEM_UI_FLAG_HIDE_NAVIGATION // hide nav bar
| View.SYSTEM_UI_FLAG_FULLSCREEN // hide status bar
| View.SYSTEM_UI_FLAG_IMMERSIVE);
}
To come out of immersive mode, just use the following method:
private void showSystemUI() {
getWindow().getDecorView().setFitsSystemWindows(true);
getWindow().getDecorView().setSystemUiVisibility(
View.SYSTEM_UI_FLAG_LAYOUT_STABLE
| View.SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION
| View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN);
}
An app hides the action bar in the following way:
uiOptions = View.SYSTEM_UI_FLAG_HIDE_NAVIGATION| View.SYSTEM_UI_FLAG_FULLSCREEN
| View.SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION
| View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN
| View.SYSTEM_UI_FLAG_LAYOUT_STABLE;
//Hide both the status bar and navigation bar
getWindow().getDecorView().setSystemUiVisibility(uiOptions);
When the screen is touched, the following method is called to show the action bar:
uiOptions = View.SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION
| View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN
| View.SYSTEM_UI_FLAG_LAYOUT_STABLE;
decorView.setSystemUiVisibility(uiOptions);
Everything works as expected except when the overflow menu is opened after the 3-dot is tapped, onMenuOpened of the activity is not called, but the menu is opened normally.
Could anyone shed some light on this?
Possibly this.
The reason that onMenuOpened() and onPanelClosed() are not called is
that Activity's default implementations of those methods will try and
init the framework Action Bar.