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
Related
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
Since the device I am developing has physical buttons, I do not want to see a navigation bar taking up my screen space. Rowboat-android on Beagleboneblack shows the navigation bar by default. Where do I turn it off?
EDIT: I am not developing applications. I am developing a Beaglebone based device. I want to remove the bar globally from the system. Somewhere there should be a code or setting in the Android source.
Found the answer at Building a wireless Android device using BeagleBone Black
Basically I edited device/ti/beagleboneblack/overlay/frameworks/base/core/res/res/values/config.xml file to set this entry:
<bool name="config_showNavigationBar">false</bool>
You should use IMMERSIVE flag like this:
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 // hide nav bar
| View.SYSTEM_UI_FLAG_FULLSCREEN // hide status bar
| View.SYSTEM_UI_FLAG_IMMERSIVE);
}
For more info, I recommend you to take a look at here.
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.
I have been searching the answer about this question for two days but I didnt find.
I'm trying to hide the action bar in order to show an image properly, but whenever I hide/show the action bar the activity show a white space at the bottom. I know that it happens because the window resize on hide/show action bar event, also that is a default animation from Android, but I need to change that color (black color) or not show this white space. But how can I do it?
I've tried to set the activity background in black, but it still not working.
E.g. USA Today app do it at the section "Day in pictures"
Please any help is apreciated!
Thanks in advance.
Have you tried setting the action bar to overlay the content area instead of resting on top of it? In your onCreate(), add this at the top just after calling super.onCreate():
getWindow().requestFeature(Window.FEATURE_ACTION_BAR_OVERLAY);
this code worked for me like a charm
// 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.
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 // hide nav bar
| View.SYSTEM_UI_FLAG_FULLSCREEN // hide status bar
| View.SYSTEM_UI_FLAG_IMMERSIVE);
}
private void showSystemUI() {
//make nav bar transparent
Window window = getWindow();
window.setFlags(WindowManager.LayoutParams.FLAG_TRANSLUCENT_NAVIGATION, WindowManager.LayoutParams.FLAG_TRANSLUCENT_NAVIGATION);
View decorView = window.getDecorView();
decorView.setSystemUiVisibility(
View.SYSTEM_UI_FLAG_LAYOUT_STABLE
| View.SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION
| View.SYSTEM_UI_FLAG_IMMERSIVE
| View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN);
}
Maybe, you have set up the following property that sets the padding of the Layout of the Activity:
android:paddingTop="?attr/actionBarSize"
You just have to remove this property.
There should be no need to do what Karakuri suggests; hide all menu items in the action bar and the bar will disappear.