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.
Related
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"
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
I have an Android app which uses the immersive sticky mode and it works well on previous versions of Android as well as on Android P, but when turning on the option of simulating a display cutout (notch), the content starts right below the status bar, leaving a blank space.
My code is standard immersive code:
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);
Any ideas?
Thank you.
Nevermind, on a real device it's a totally normal behavior, because you don't want fullscreen content to be obscured by the notch (although the iPhone X does it).
Leaving this question for future reference.
We can have full immersive experience if required for devices with display cutout by setting the window layout attribute. This is documented here.
<item name="android:windowLayoutInDisplayCutoutMode" tools:targetApi="o_mr1"> shortEdges</item>
THis solved my problem.
I have AppcompatActivity (appcompat-v7:25.3.1) which is in full screen mode using the below code. But the problem is that when in full screen mode and navigationview is displayed it shows these black overlay bar on top and bottom of it in Android 6.0, equal to the sizes of status bar and navigation bar.
Navigation view after applying the below mentioned flags (Can't embed images for now :( )
private void hideAndroidNavigation() {
getWindow().addFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN);
getWindow().addFlags(WindowManager.LayoutParams.FLAG_TRANSLUCENT_NAVIGATION);
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);
}
In Android 4.4 however the black overlay simply turns to white
as you can see in this image.
I was able to remove the overlay for the status bar using following code:
getWindow().addFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN);
getWindow().addFlags(WindowManager.LayoutParams.FLAG_TRANSLUCENT_NAVIGATION);
But I have no luck for the removal of the navigation bar overlay. I tried this solution https://stackoverflow.com/a/38008965/4428159, suggesting to remove View.SYSTEM_UI_FLAG_LAYOUT_STABLE but still the output was same
Is there any other way to remove these overlays or a solution specific to appcompat libraries?
Check if you have the following line fitSystemWindows=true in your layout xml and style xml, if so remove the line or set the value to false
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.