I need to completely remove the actionbarr and navigationbar from my app. So I stay in fullscreen without the possibility to swipe so I get the navigationbar back.
I have now this code in my onreate method which makes it go away but as soon as you swipe the navigation bar will appear again. How can I avoid this?
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);
On your activity override onBackPressed() to prevent activity from going back when back button is pressed. By default it runs finish() method if there is no backStack to run through.
On your App theme for the activity, make sure it's a theme that has NoActionBar on it that way it won't have one unless you put one into layout.
style name="AppTheme" parent="Theme.AppCompat.Light.NoActionBar"
Related
I recently converted my app to Single Activity architecture and trying to set the one particular fragment to fullscreen. The standard fullscreen code for activity does not work for fragments
final int flags =
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 found this Android set full screen from fragment. But settings it to FLAG_LAYOUT_NO_LIMITS causes the PagerSnapHelper in the fragment to jump around when switching between FLAG_LAYOUT_NO_LIMITS and revoking it.
So my question is, is there any other way to set fragment to fullscreen without using FLAG_LAYOUT_NO_LIMITS.
You shouldn't ever need to use FLAG_LAYOUT_NO_LIMITS, nor should you apply fitsSystemWindows="true" globally at your activity layer - that is what would prevent your fragment from going full screen. Instead, only add fitsSystemWindows on the fragments / individual components that would otherwise overlap the status/system bars. This would ensure that your full screen fragment would be able to take up the full size and not be inset from the edges.
I'm trying to hide the top and bottom navigation bars on Android devices when I run my app. Right now, I have modified my "onWindowFocusChanged" and "onCreate" methods to have the following code fragment:
final int screen =
View.SYSTEM_UI_FLAG_HIDE_NAVIGATION |
View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN |
View.SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION |
View.SYSTEM_UI_FLAG_LAYOUT_STABLE |
View.SYSTEM_UI_FLAG_IMMERSIVE_STICKY |
View.SYSTEM_UI_FLAG_FULLSCREEN;
getWindow().getDecorView().setSystemUiVisibility(screen);
However, when I go back to the home screen on Android without closing the app, reopen my app, and then try to switch between pages on my app, the navigation bar briefly appears and then disappears between these switches. I assume this is because the above methods are not being accessed.
How can I make sure that even when a user abruptly switches out of my app and then back into it, that the navigation bar will not briefly reappear when switching pages as a result?
Thanks for the help.
You can look at the guide here: https://developer.android.com/training/system-ui/navigation
You need to add the code to three places:
onWindowFocusChanged, onCreate and onResume
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);
In styles I've
<item name="android:windowFullscreen">true</item>
<item name="android:windowNoTitle">true</item>
and in the manifest file, in application I've specified my theme, but home button and back button are still visible, what should I do?
You must use Immersive feature of android. Immersive mode will be only working on devices with KitKat and higher. This, what is weird on your side, is fact, that basing on your words, you cannot even get these flags like this:
View.SYSTEM_UI_FLAG_HIDE_NAVIGATION | View.SYSTEM_UI_FLAG_FULLSCREEN | View.SYSTEM_UI_FLAG_LAYOUT_STABLE | View.SYSTEM_UI_FLAG_IMMERSIVE_STICKY | View.SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION;
(or part of them). If it is this way, then it is looking, that your compileSdkVersion is lower, than it should be. On start I would advise you to update compileSdkVersion.
When you will do this, and you would like to use these flags please in places, where you want to use immersive mode add conditions, that will be looking like this:
if (Build.VERSION.SDK_INT >= VERSION_CODES.KITKAT) {
int UI_OPTIONS = View.SYSTEM_UI_FLAG_HIDE_NAVIGATION | View.SYSTEM_UI_FLAG_FULLSCREEN | View.SYSTEM_UI_FLAG_LAYOUT_STABLE | View.SYSTEM_UI_FLAG_IMMERSIVE_STICKY | View.SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION;
getWindow().getDecorView().setSystemUiVisibility(UI_OPTIONS);
}
Then it should not mess on older OS.
Use the following two way to achieve what you need
getActionBar().setDisplayHomeAsUpEnabled(false) to remove the home
button from the action bar.
ActionBar().setHomeAsUpIndicator(null);
getSupportActionBar().setHomeAsUpIndicator(null);
i prefer you use the first 1
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.