I've followed this thread to hide Navigation bar:
Hide ICS back home task switcher buttons
Works fine when the Activity starts, but whenever I press anywhere on the screen the Navigation bar appears again. I've tried this on an empty Activity without any "views" except the Content View.
How can I hide it throughout the duration of my Activity without having to add some kind of Timer or a Thread to just hide it every millisecond?
It would be great to gain some extra screen size or be able to customize my own Navigation Bar throughout my App.
if( Build.VERSION.SDK_INT >= Build.VERSION_CODES.ICE_CREAM_SANDWICH )
getWindow().getDecorView().setSystemUiVisibility( View.SYSTEM_UI_FLAG_HIDE_NAVIGATION );
else if( Build.VERSION.SDK_INT >= Build.VERSION_CODES.HONEYCOMB )
getWindow().getDecorView().setSystemUiVisibility( View.STATUS_BAR_HIDDEN );
This is a problem that came in a long time when we need to show som content in full screen, bumped the difficulty in being able to hide the status bar on some versions of Android:
Finally Google’s latest Android OS, KitKat, introduces a decent user-friendly tool that gives us ownership of that last bit of screen.
Using Immersive Full-Screen Mode see more in : https://developer.android.com/training/system-ui/immersive.html
// This snippet hides the system bars.
private void hideSystemUI() {
// Set the IMMERSIVE flag.
// Set the content to appear under the system bars so that the content
// doesn't resize when the system bars hide and show.
mDecorView.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);
}
// This snippet shows the system bars. It does this by removing all the flags
// except for the ones that make the content appear under the system bars.
private void showSystemUI() {
mDecorView.setSystemUiVisibility(
View.SYSTEM_UI_FLAG_LAYOUT_STABLE
| View.SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION
| View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN);
}
Here's how this has been a thorn in : http://blog.grio.com/2014/02/androids-hiding-of-the-system-bar-fixed.html
Related
There is a way to completly hide the support action bar, even if the user scroll down from top to bottom? Never show it.
This solution works but only temporary
getSupportActionBar().hide();
I've tried also:
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);
and
android:theme="#style/Theme.AppCompat.NoActionBar"
or similar.
When the user scroll down, the bar re-appear.
I need it because i'm making my personal launcher and I've got my personal support action bar
When the user scroll down, the bar re-appear.
It seems to me it's not available to completely disable/hide status bar.
From SYSTEM_UI_FLAG_IMMERSIVE_STICKY docs:
When system bars are hidden in immersive mode, they can be revealed temporarily with system gestures, such as swiping from the top of the screen. These transient system bars will overlay app’s content, may have some degree of transparency, and will automatically hide after a short timeout.
Use this
getWindow().addFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN);
I tried setting systemUIView(View.GONE) and use Immersive Full-Screen Mode. But users can always get the naviagtion bar back by touching the bottom of the screen. The apps i mentioned above are able to hide it without root or setting default launcher.
Okay, I found a solution finally and here is how it's done:
Use SYSTEM_UI_FLAG_IMMERSIVE_STICKY to hide the navigation bar as follow, you may put the code inside onResume of your activity
View decorView = getWindow().getDecorView();
int uiOptions = View.SYSTEM_UI_FLAG_HIDE_NAVIGATION |View.SYSTEM_UI_FLAG_IMMERSIVE_STICKY;
decorView.setSystemUiVisibility(uiOptions);
Then, add a system error window using WindowManger and overlay it on top of everything
you can put this unescapable view anywhere you like, but if you want to do it while users locked the screen, add this flag:
getWindow().setFlags(WindowManager.LayoutParams.FLAG_SHOW_WHEN_LOCKED, WindowManager.LayoutParams.FLAG_SHOW_WHEN_LOCKED);
Et voilà
Well I've never achieved this but it seems that you will need to set some other flags to get this kind of view :
When you use the SYSTEM_UI_FLAG_IMMERSIVE flag, it hides the system bars based on what other UI flags you have set (SYSTEM_UI_FLAG_HIDE_NAVIGATION, SYSTEM_UI_FLAG_FULLSCREEN, or both). When the user swipes inward in a system bars region, the system bars reappear and remain visible.
Here is a snippet that you can use to set these flags :
// This snippet hides the system bars.
private void hideSystemUI() {
// Set the IMMERSIVE flag.
// Set the content to appear under the system bars so that the content
// doesn't resize when the system bars hide and show.
mDecorView.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);
}
// This snippet shows the system bars. It does this by removing all the flags
// except for the ones that make the content appear under the system bars.
private void showSystemUI() {
mDecorView.setSystemUiVisibility(
View.SYSTEM_UI_FLAG_LAYOUT_STABLE
| View.SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION
| View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN);
}
For more information go check Using Immersive Full-screen Mode from the android developer website.
Hope this help.
I use the android:Theme.Light.NoTitleBar.Fullscreen for setting the layout as the full screen and without a Title Bar. But now I have a problem. some android devices have the additional tools like the Navigation bar and when I run my app in the devices, because there are the additional tools like the Navigation bar in the android devices, as the result my app is not Full Screen really and I see the Navigation bar still. Are there a way to solve this problem? How Can I create my app as Full Screen in all version of the android (API 7 to higher) really?
You can force notification bar like this:
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
requestWindowFeature(Window.FEATURE_NO_TITLE);
getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN,
WindowManager.LayoutParams.FLAG_FULLSCREEN);
setContentView(R.layout.main);
}
But the Navigation Bar is not going to go... only on API lvl 19+ (4.4+) and it's called "Immersive mode". You can hide it and show it like this:
// This snippet hides the system bars.
private void hideSystemUI() {
// Set the IMMERSIVE flag.
// Set the content to appear under the system bars so that the content
// doesn't resize when the system bars hide and show.
mDecorView.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);
}
// This snippet shows the system bars. It does this by removing all the flags
// except for the ones that make the content appear under the system bars.
private void showSystemUI() {
mDecorView.setSystemUiVisibility(
View.SYSTEM_UI_FLAG_LAYOUT_STABLE
| View.SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION
| View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN);
}
For more info, check the official documentation: https://developer.android.com/training/system-ui/immersive.html
I've got a problem with status bar in kiosk mode App.
I want to know how to hide status bar and I know that is it possible to disable it permanently in 4.4.2 Kitkat? But I found nice app -KioWare.
There is cool mode when I grab status bar down, it is running back to the top very quickly. In 0.05 sec. I am not able to click anything. And this is what I'm looking for.
I can't buy this app because it's to expensive and I only need this magic trick with status bar. Anyone can help me ? It should be only few lines of code.
I wrote an article that covers this question, but specifically for Lollipop. I'm not sure if the immersive mode in Android 5 will also apply for 4.4.2, but it's something to try out maybe?
http://www.sureshjoshi.com/mobile/android-kiosk-mode-without-root/
#Override
protected void onResume() {
super.onResume();
hideSystemUI();
}
// This snippet hides the system bars.
private void hideSystemUI() {
// Set the IMMERSIVE flag.
// Set the content to appear under the system bars so that the content
// doesn't resize when the system bars hide and show.
mDecorView.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_STICKY);
}
I want to use the "immersive mode" in my app.
I am following the documentation and working properly:
private View mDecorView;
...
#Override
public void onWindowFocusChanged(boolean hasFocus) {
super.onWindowFocusChanged(hasFocus);
if (hasFocus) {
mDecorView.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);
}
}
...
#Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.test);
mDecorView = getWindow().getDecorView();
}
This enables immersive full-screen mode.
My problem is that I want to use only FLAG_IMMERSIVE_STICKY, as the same result as the Trello app:
The bars are transparent and are always visible.
I searched for information and different combinations, but I get the result I want.
I appreciate any help.
Thank you!
Trello is using translucent bars [1], not immersive mode, with a custom transparent action bar background.
[1] https://developer.android.com/about/versions/android-4.4.html#TranslucentBars
The documentation also states that you have to set the UI Flags for the activity in the onCreate method.
- https://developer.android.com/training/system-ui/immersive.html
Implement these two methods and call hideSystemUI in the onCreate method
// This snippet hides the system bars.
private void hideSystemUI() {
// Set the IMMERSIVE flag.
// Set the content to appear under the system bars so that the content
// doesn't resize when the system bars hide and show.
mDecorView.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);
}
// This snippet shows the system bars. It does this by removing all the flags
// except for the ones that make the content appear under the system bars.
private void showSystemUI() {
mDecorView.setSystemUiVisibility(
View.SYSTEM_UI_FLAG_LAYOUT_STABLE
| View.SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION
| View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN);
}
This should hide the statusBar and the navigationBar.
The documentation states that this should hide both, navigation and statusbar.
For me it just hides the StatusBar.
I hope this helps.
The flags you're looking for are:
WindowManager.LayoutParams.FLAG_TRANSLUCENT_STATUS and
WindowManager.LayoutParams.FLAG_TRANSLUCENT_NAVIGATION
You can also use the flags in your theme using:
<item name="android:windowTranslucentStatus">true</item>
<item name="android:windowTranslucentNavigation">true</item>
Unfortunately, it won't immediately appear like the Trello app if your app uses an action bar. You'll have to use some tricks/hacks to make it look like the Trello app. In the case that your app uses action bars, you could save yourself the time and use this library instead*. Needless to say, this will only work on API 19+.
*Personally, I don't endorse use of transparent system bars just for the sake of extending action bar colors. I feel it should only be used if you have content to show underneath the system bars or if you have a full-screen activity.