I want to hide the soft key bar (home, back, menu) when a user launches my app. I tried using:
getWindow().getDecorView().setSystemUiVisibility(View.SYSTEM_UI_FLAG_HIDE_NAVIGATION);
But unfortunately as soon as the user interacts with my app, the soft key bar shows again. Is there any way to hide it till the user exits my app?
This is called immersive mode.
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);
}
}
Happy???
Related
I am trying to set my activity to full screen using this code below:
private void hideSystemUI() {
View decorView = getWindow().getDecorView();
decorView.setSystemUiVisibility(
View.SYSTEM_UI_FLAG_IMMERSIVE_STICKY
| 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);
}
But I am getting a black color navigation bar on certain phones because of the condition on settings -> display where certain phones need to permit apps to use a fullscreen mode. To address this issue I decided that I need to implement a permission checker when the activity inflates. If there is another way please tell me and I will try to implement it.
Edit:
Here is the link of the conditions for phones that I am talking about:
https://www.gottabemobile.com/how-to-enable-full-screen-apps-on-galaxy-s10/
this problem happen with me for 2 different devices and this because of the front camera notch or screen cutout.
I used this code in oncreate() :
hideSystemUI();
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.P) {
getWindow().getAttributes().layoutInDisplayCutoutMode =
WindowManager.LayoutParams.LAYOUT_IN_DISPLAY_CUTOUT_MODE_SHORT_EDGES; }
Or in the theme style xml file add this line :
<item name="android:windowLayoutInDisplayCutoutMode">shortEdges</item>
In your manifest file put
android:theme="#style/Theme.Design.NoActionBar"
or
android:theme="#style/AppTheme"
and in your activity call hideSystemUI(); before setting the content view
like this :
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;
getWindow().getDecorView().setSystemUiVisibility(flags);
setContentView(R.layout.activity_main);
I need to enter android immersive mode in my react-native app, but when I try View.SYSTEM_UI_FLAG_IMMERSIVE) I got a lot of errors during compilation. I don't know anything about native android development and do it blindfold. So can you please briefly explain what and where I need to past to make it work.
I need only to automatically hide android navigation buttons on app start so it's enough to add few lines of code in MainActivity.java:
#Override
protected void onStart()
{
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);
super.onStart();
}
what about adding android:theme="#android:style/Theme.NoTitleBar.Fullscreen" in your android manifest xml file??
I know how to make an activity with a full screen in android , but i want to know if there is a way to disable the auto appear of statusBar when clicking in the top of the screen , i want to make it like in games .
Well You Can make Full screen In Immersive and Non_Immersive
You are talking about immersive fullscreen
Use This Code
#Override
public void onWindowFocusChanged(boolean hasFocus) {
super.onWindowFocusChanged(hasFocus);
if (android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.KITKAT) {
if (hasFocus) {
decorView
.setSystemUiVisibility(View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN
| View.SYSTEM_UI_FLAG_HIDE_NAVIGATION
| View.SYSTEM_UI_FLAG_FULLSCREEN
| View.SYSTEM_UI_FLAG_IMMERSIVE_STICKY);
}
}
}
ANd You Can go Through this page To Know More
https://developer.android.com/training/system-ui/immersive.html
I'm developing a video playing app using the latest YouTube API.
In my
PlayAll extends YouTubeBaseActivity implements YouTubePlayer.OnInitializedListener
-class
I set:
View decorView = getWindow().getDecorView().findViewById(android.R.id.content);
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
);
My problem is that when playing video the navigation dar does get hidden but doesn't become sticky. Meaning that when touching the screen it will appear again. My intention is to hide it and that the user have to swipe up-down or right hand side to left to reveal it.
The strange thing is that if I leave the app during a video playing and the return to it the immersive mode will work!
What am I doing wrong? Something in the YouTube-classes that breaks my immersive mode?
Thanks!
/Jonas
If you haven't solved this issue yet, have you tried moving the flags to the overridden method as follows:
#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);
}
}
In a fragment I have implemented a GestureDetector.SimpleOnGestureListener so that I can enter/exit immersive mode when onSingleTapUp is detected.
A FragmentStatePagerAdapter is used to move between these fragments on swipe left/right. If you enter immersive mode then swipe to a new fragment the UI remains in immersive mode.
However, in the onCreateView method of the new fragment I need to detect whether the UI is in immersive mode to when creating my listener.
I have tried calling getSystemUiVisibility() on the new view but this returns SYSTEM_UI_FLAG_VISIBLE.
Is there a method for detecting whether the application is in immersive mode from any view or fragment regardless of whether that initiated the transition to immersive mode?
If anyone is looking for a more in-depth answer. To check if the window is in immersive vs non-immersive you can do something use:
(getWindow().getDecorView().getSystemUiVisibility() & View.SYSTEM_UI_FLAG_IMMERSIVE) == View.SYSTEM_UI_FLAG_IMMERSIVE
An example of it's usage for swapping between immersive and normal:
private void toggleImmersive() {
if ((getWindow().getDecorView().getSystemUiVisibility() & View.SYSTEM_UI_FLAG_IMMERSIVE) == View.SYSTEM_UI_FLAG_IMMERSIVE) {
getWindow().getDecorView().setSystemUiVisibility( // Go fullscreen
View.SYSTEM_UI_FLAG_LAYOUT_STABLE
| View.SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION
| View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN);
} else {
getWindow().getDecorView().setSystemUiVisibility( // Go immersive
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);
}
}
#Mark, it sounds like you may have gotten it resolved based on my previous comment: use a View owned by the Activity to call getSystemUiVisibility() rather than the Fragment.