Keep Navigation Bar hidden - android

I am writing a fullscreen application, and I need to KEEP the navBar hidden,
I am using View.SYSTEM_UI_FLAG_HIDE_NAVIGATION But the bar will reappear as soon as there is an interaction from the user,
I found some other questions, but none have the answer ... so have anyone succeeded ?
Thank you in advance

Add the following line under your activity in Manifest File and it will make you r activity full screen
android:theme="#android:style/Theme.NoTitleBar.Fullscreen"

You can't hide completely NavigationBar, it will ALWAYS reappear after user interaction.

Would be nice if you posted what you have already tried.
I use this to temporarily hide my actionbar:
getWindow().requestFeature(Window.FEATURE_ACTION_BAR);
getActionBar().hide();
The code is at the beginning of onCreate

Using only View.SYSTEM_UI_FLAG_HIDE_NAVIGATION, the first touch event is consumed by the system, and the navigation bar will reapear.
If you are coding for KitKat(4.4.2) onwards, you can add this code to your onResume() method:
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);
Read more about Immersive Mode: https://developer.android.com/training/system-ui/immersive.html

This works for me.
http://www.androiddocs.com/training/system-ui/immersive.html
From the post:
The flags SYSTEM_UI_FLAG_IMMERSIVE and SYSTEM_UI_FLAG_IMMERSIVE_STICKY both provide an immersive experience, but with the differences in behavior described above. Here are examples of when you would use one flag vs. the other:
If you're building a book reader, news reader, or a magazine, use the IMMERSIVE flag in conjunction with SYSTEM_UI_FLAG_FULLSCREEN and SYSTEM_UI_FLAG_HIDE_NAVIGATION. Because users may want to access the action bar and other UI controls somewhat frequently, but not be bothered with any UI elements while flipping through content, IMMERSIVE is a good option for this use case.
If you're building a truly immersive app, where you expect users to interact near the edges of the screen and you don't expect them to need frequent access to the system UI, use the IMMERSIVE_STICKY flag in conjunction with SYSTEM_UI_FLAG_FULLSCREEN and SYSTEM_UI_FLAG_HIDE_NAVIGATION. For example, this approach might be suitable for a game or a drawing app.
If you're building a video player or some other app that requires minimal user interaction, you can probably get by with the lean back approach, available since Android 4.0 (API Level 14). For this type of app, simply using SYSTEM_UI_FLAG_FULLSCREEN and SYSTEM_UI_FLAG_HIDE_NAVIGATION should be sufficient. Don't use the "immersive" flags in this case.

Related

How to disable statusbar and navigationbar animation when activating/deactivating full-screen mode in Android

Problem
Activating and Deactivating (immersive) full-screen mode causes that the statusbar but also navigation bar "fades" in and out. The animation seem to differ across different devices and I would like to disable the animation completely. My minimum target SDK is 19; however, I would also be happy with a solution that requires a higher API level. Please see below for further details.
Running demo
I implemented a (minimal) demo so that people can test things easily. Everything is available on GitHub:
https://github.com/sztyler/android-fullscreendemo
For clarification, I am using setSystemUiVisibility(FLAGS) to activate/deactivate the full screen mode. Further, I am using the following flags:
Activating full-screen mode:
int visibility = View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN
| View.SYSTEM_UI_FLAG_HIDE_NAVIGATION
| View.SYSTEM_UI_FLAG_FULLSCREEN
| View.SYSTEM_UI_FLAG_IMMERSIVE_STICKY;
mainView.setSystemUiVisibility(visibility);
Deactivating full-screen mode:
int visibility = View.SYSTEM_UI_FLAG_VISIBLE;
mainView.setSystemUiVisibility(visibility);
What I tried
I already tried many different things and did a lot of research. In the following, I want summaries the main approaches which I already tried.
Instead of using setSystemUiVisibility (which seems to be recommended) a lot of people recommend to use getWindow().setFlags to change flags. However, setting the Flags in a different way does not seem to have an effect. I also assume that this is outdated.
how to remove statusbar animation when changing to fullscreen in Android
Hide and show statusBar with Toolbar at the same time in android
Android: Disable and enable to pulling the status bar programmatically for API 19
hide and show statusbar without any effect to layout in android
Android: show/hide status bar/power bar
It seems to be possible to exclude the status bar and navigation bar from the exit/enter fade transition when switching between activities. However, this does not seem to have any effect on activating/deactivating full-screen mode.
How do I prevent the status bar and navigation bar from animating during an activity scene animation transition?
Some people just recommend different flags (just in general to hide the bars) -but the animation stays the same.
View.setSystemUiVisibility(View.STATUS_BAR_HIDDEN);
Android: Ability to Auto-Hide the Title/Status Bars?
Some people highlight that it is possible to override the subsequent animation with overridePendingTransition(0, 0)
but this does not seem so work in this case.
Is there any way to remove notification/status bar, but not in onCreate?
How the animation can look like
Just to clarify what I mean. In the following, there are gif animations which show the status/navigation bar animation (Sorry I don't have the permission to embed images)
Android 8.0 / Huawei / There is no fade out animation (both bars just vanish as required but there is a fade in animation). Both statusbar and navigationbar "flash in".
Statusbar Animation
Navigationbar Animation
Android 5.0 / Samsung / There is a fade in and fade out animation (There is no navigationbar).
Statusbar Animation
(The behavior of the actionbar is as expected.)

When Android automatically exits Immersive Sticky it does not resize views so they are blocked

I have an activity which can go to Immersive Sticky Full Screen on the click of the button. This button does the following code in order to get into Immersive Sticky Full Screen.
getActivity().getWindow().getDecorView().setSystemUiVisibility(
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);
Note: I specifically do NOT include the following tag as if I do, it breaks the layout of my screen when I exit Immersive Sticky Full Screen.See my other question: Android closing full screen view at the bottom is shunted off the screen
View.SYSTEM_UI_FLAG_LAYOUT_STABLE
When Android is in Immersive Sticky Full Screen when another view is displayed, such as a DialogFragment, a AlertDialog, keyboard comes up, Android automatically takes you out of Immersive Sticky Full Screen by showing the Status Bar and on screen navigation bar. However it does NOT resize the views in my application, so now my views are underneath the navigation bar and I can not get to any of the buttons at the bottom of my screen. I have tested with the "View.SYSTEM_UI_FLAG_LAYOUT_STABLE" flag and it makes no difference, the views are still not resized.
This seems a massive flaw in Android's behavior and surely I am doing something wrong. How can I get it to resize my views when it displays the status bar and Navigation bar?
I can work around some cases, such as Dialogs popping up by using the code in the following SO question, https://stackoverflow.com/a/24549869/2663916 but I have lots of possible things that could popup on my full screen view and I don't want to have to put that hack in every single place to keep it in immersive full screen. Furthermore, when the keyboard comes up I DO want the navigation bar to appear.
Surely Android should adjust the on screen views when it is displaying the on screen bars.
Re-reading Google docs made it obvious that the cause was the inclusion of the following two flags
View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN // this STOPS Android resizing my view to be below the status bar when it is displayed
View.SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION // this STOPS Android resizing my view to be above the nav bar when it is displayed
https://developer.android.com/training/system-ui/immersive.html
"It's good practice to include other system UI flags (such as SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION and SYSTEM_UI_FLAG_LAYOUT_STABLE) to keep the content from resizing when the system bars hide and show. You should also make sure that the action bar and other UI controls are hidden at the same time. "

Overriding system UI visibility flags used by the exit immersive view system gesture

In an Android application I added support for exiting immersive view via a single tap. I use the
View.SYSTEM_UI_FLAG_VISIBLE
flag to ensure the fragment gets resized and that action bar doesn't overlap the fragment.
When you exit immersive view via the standard system gesture, the action bar overlaps the fragment. I assume this is due to using the standard flags detailed here under "Using Non-Sticky Immersion" e.g.
// 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);
}
I would like exiting immersive via the system gesture to behave in the same way as my single tap implementation. Is it possible to override the system UI flags used by the system gesture?
There is no way override the default gesture flags.
If what you want is to resize your fragment when the system bars become visible, you should register a View.OnSystemUiVisibilityChangeListener to mDecorView. This listener will be notified of system UI changes. Once you get a notification that the bars come visible (whatever the reason) you can do the necessary changes to resize your fragment. See https://developer.android.com/training/system-ui/visibility.html for an example on how the listener can be used.

How to hide the soft-key bar on Android phone?

 
When my app starts, I'd like to hide the soft keys bar (in red rectangle) to have a larger screen.
How can I hide it?
Do I need to show the bar purposely when the app quits? Or it will restore itself automatically after the app quits?
Android 4.1, with no hardware keys on phone front.
I know its late but it is the right answer so what you are trying to do is what called immersive mode. for (API 19)
check out: https://developer.android.com/training/system-ui/immersive.html
The code that you were asking for is:
#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_STICKY);
}
}
Try
getWindow().getDecorView().setSystemUiVisibility(View.SYSTEM_UI_FLAG_HIDE_NAVIGATION);
From official doc
The SYSTEM_UI_FLAG_LOW_PROFILE flag replaces the STATUS_BAR_HIDDEN
flag. When set, this flag enables “low profile" mode for the system
bar or navigation bar. Navigation buttons dim and other elements in
the system bar also hide. Enabling this is useful for creating more
immersive games without distraction for the system navigation buttons.
The SYSTEM_UI_FLAG_VISIBLE flag replaces the STATUS_BAR_VISIBLE flag
to request the system bar or navigation bar be visible.
The SYSTEM_UI_FLAG_HIDE_NAVIGATION is a new flag that requests the
navigation bar hide completely. Be aware that this works only for the
navigation bar used by some handsets (it does not hide the system
bar on tablets). The navigation bar returns to view as soon as the
system receives user input. As such, this mode is useful primarily for
video playback or other cases in which the whole screen is needed but
user input is not required.
The behavior of the nav bar is app dependent IIRC, so it should show again after the user leaves your app.

Is there a way to hide the system/navigation bar in Android ICS

I'd like to extend the discussion regarding hiding of the system/navigation bar at the bottom of the screen on Android Ice Cream Sandwich (4.0 and up) tablet devices.
There's already a thread ( Is there a way to hide the system bar in Android 3.0? It's an internal device and I'm managing navigation ) about hiding the bar on Honeycomb devices. My clients, however, will be using the newest Ice Cream Sandwich devices and are very keen on hiding the bar at the bottom the screen. Their application is not for regular consumer use and it's very important for them to take over the whole screen to provide their experience. How possible is it to hide this bar -- or at least, override the behaviour of all the buttons -- without rooting the devices or rewriting its firmware?
Check out SYSTEM_UI_FLAG_HIDE_NAVIGATION, this flag hides the navigation bar until the user interacts with the device. It was introduced in Android 4.0. You can enable this flag for example like this:
getWindow().getDecorView()
.setSystemUiVisibility(View.SYSTEM_UI_FLAG_HIDE_NAVIGATION);
Note that the navigation won't disappear again automatically, you have to set it every time after the user interacted with the device.
Alternatively you can make the navigation less obtrusive by using SYSTEM_UI_FLAG_LOW_PROFILE, this changes the buttons into small dots (e.g. like the camera app).
on rooted devices, i use the following adb command
adb shell pm disable com.android.systemui
to hide navigation bar permanently. To show it again, run
adb shell pm enable com.android.systemui
so far it's working fine for me
Using the below code is one way of doing it to hide navigation
getWindow().getDecorView()
.setSystemUiVisibility(View.SYSTEM_UI_FLAG_HIDE_NAVIGATION);
But the problem with the above is that it becomes visible as soon as user touches the screen.
In Android Kitkat there is a feature called as IMMERSIVE which hides the notification bar and the navigation. It does not show even if the user interacts with the screen. However the user can make it visible by swiping it from top of the screen to bottom. Below is the code to achieve it
//Initializew this in onCreate()
View mDecorView = getWindow().getDecorView();
//Then call this function
private void hideSystemUI() {
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_LOW_PROFILE
| View.SYSTEM_UI_FLAG_IMMERSIVE);
}
However in my case I never wanted the navigation and notification bar to be visible even if the user swipes from top of the screen to bottom. I gave it a try and I was able to achieve it partially. What I did was I implemented a CountDownTimerwhich would call hideSystemUI() every second or so. I know it is not the best way of doing it. But I did not get any other solution to do it.
If someone gets any then please let me know on how to permanently hide navigation and notification bar :) Hope this answer helps some one in future :)
Watch this video to better understand about this feature.
Update - there is a work around which can be used for such cases (manually setting up the app for the client). Indeed, the navigation bar can't be removed within the given framework.
However, there is a solution to hide the navigation bar if rooting the device is an option for you. Here is how:
Root device
Install and run Busybox
Install HideBar
In HideBar there is an option to run in 'Kiosk' mode, in which there is no way to re-display the navigation bar. Needless to say, you really need to be careful with this.
Risks involved:
bricking the device
getting the installation of BusyBox wrong, which could get things a bit tricky, although is very unlikely to cause loss of information.
getting into a stalemate where you can't quit your app. For example if 1 your GUI doesn't provide a close option, 2 your app start automatically on start-up, 3 HideBar doesn"t allow any way of re-displaying the navigation bar and 4 HideBar hids the navigation bar on startup. However this can be overcome by simply stopping/uninstalling your app from adb.
Here are other identical questions:
Android tablet navigation bar won't hide
How to remove system bars on Android, I mean, all
Android tablet navigation bar won't hide
Is there a way to hide the system/navigation bar in Android ICS
Hide Tablet system bar
Real Fullscreen with Android 4 Tablets
Easy way to hide system bar on Android ICS
Although it's a hacky solution, I think it deserves attention because does not require rooting the device:
getWindow().getDecorView().setSystemUiVisibility(8);.
To hide status bar and navigation bar in android ics use
LinearLayout layout = (LinearLayout)findViewById(R.id.layout);
layout.setSystemUiVisibility(View.SYSTEM_UI_FLAG_HIDE_NAVIGATION);
EDIT: As of 4.4 (19) you can use the following to enable what is called "IMMERSIVE MODE". It was introduced for Google's Cardboard vrtoolkit, but can be used generally.
setSystemUiVisibility(View.SYSTEM_UI_FLAG_IMMERSIVE)
https://developer.android.com/training/system-ui/immersive.html
From my efforts, it seems that:
setSystemUiVisibility(View.SYSTEM_UI_FLAG_HIDE_NAVIGATION)
does not work on tablets.
It does work on smartphones (tested with a Nexus 4 Mako), but it will reappear on a touch/click event.
This also seems to capture focus to the bar, forcing you to click twice to regain focus to the view.
I have been trying to find a way to trap the event that actually redisplays the bar. No luck.
Being stubborn, I am going to download the android os code, fire up the eclipse debugger and go a-huntin. This is not a bug - the nav bar is crucial to app lifecycle.
I have seen apps do it (games and such) so there is a way without rooting.
place this code in your application tag in manifest file to hide default tab bar
<Application
android:theme="#android:style/Theme.Black.NoTitleBar.Fullscreen" <!--
other parameters of application tag-->
>
and the then make a linear or relative layout and place it in your activity layout.
You can not hide it unless you have rooted the device. But of course there is a workaround which might not fit with your requirement but several well known apps in the market at the moment using this strategy to achieve this disable menu bar feature for their apps.
Grant admin privilege.
Set password & lock the device using device admin profile api
Then load what ever the UIs on top of the native lock screen. (Of course this will show background lock screen whenever a transition happens between activities. But if logic is organized well, then it will be smooth & less noticed by the user)
When need to enable back, reset password to "" using resetPassword("", 0) of device policy manager object.
may be is the button behavor is enought you can have a look in my answer here
you still have the bar but you can't exit app without reboot tablet
You can hide the navigation bar on Android 4.0 and higher using the SYSTEM_UI_FLAG_HIDE_NAVIGATION flag. This snippet hides both the navigation bar and the status bar:
View decorView = getWindow().getDecorView();
// Hide both the navigation bar and the status bar.
// SYSTEM_UI_FLAG_FULLSCREEN is only available on Android 4.1 and higher, but as
// a general rule, you should design your app to hide the status bar whenever you
// hide the navigation bar.
int uiOptions = View.SYSTEM_UI_FLAG_HIDE_NAVIGATION
| View.SYSTEM_UI_FLAG_FULLSCREEN;
decorView.setSystemUiVisibility(uiOptions
See the following: Hiding the Navigation Bar
If your device is rooted this code will help you to hide system bar on ICS (I tested it on Samsung Galaxy Tab 2 and it works excellent):
ArrayList<String> list = new ArrayList<String>();
Map<String, String> env = System.getenv();
for (String envName : env.keySet()) {
list.add(envName + "=" + env.get(envName));
}
// Array containing the environment to start the new process in
String[] envp = (String[]) list.toArray(new String[0]);
String hidingCommand = "while [ true ]\n" + "do\n" + "killall com.android.systemui\n" + "done\n";
Runtime.getRuntime().exec(new String[] { "su", "-c", command }, envp);
myContext.sendBroadcast(new Intent("com.mycompany.myapp.ACTION_BARHIDDEN"));

Categories

Resources