My app consists of a ViewPager that displays images and videos. The app should go into immersive view on a tap, and come out of immersive view on a tap of after 3 seconds. I also want the status bar to always be hidden. This mostly works, however...
I'm using a variation of the SystemUIHider classes that are generated in Android Studio. I've created a new class called SystemUIHiderKitKat which uses these flags.
Clicking on the screen will show the navigation and actionbar (not the status bar). Clicking within 3 seconds will hide the navigation and status bar. And waiting more than 3 seconds will automatically hide the navigation and actions bars.
Video of the bars functioning as expected, but without the MediaController : Working
Video of bars not working correctly when MediaController is toggled : Not Working
mShowFlags = View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN
| View.SYSTEM_UI_FLAG_LAYOUT_STABLE
| View.SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION
| View.SYSTEM_UI_FLAG_FULLSCREEN;
mHideFlags = View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN
| View.SYSTEM_UI_FLAG_LAYOUT_STABLE
| View.SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION
| View.SYSTEM_UI_FLAG_FULLSCREEN
| View.SYSTEM_UI_FLAG_LOW_PROFILE
| View.SYSTEM_UI_FLAG_HIDE_NAVIGATION
| View.SYSTEM_UI_FLAG_IMMERSIVE;
mTestForHiddenFlags = View.SYSTEM_UI_FLAG_LOW_PROFILE | View.SYSTEM_UI_FLAG_HIDE_NAVIGATION;
My VideoView and MediaController are both members of a custom FrameLayout class
public class MyVideoView extends FrameLayout
{
setOnSystemUiVisibilityChangeListener(new OnSystemUiVisibilityChangeListener()
{
#Override
public void onSystemUiVisibilityChange(int visibility)
{
final int hidden = SYSTEM_UI_FLAG_LOW_PROFILE | SYSTEM_UI_FLAG_HIDE_NAVIGATION | SYSTEM_UI_FLAG_FULLSCREEN;
if ((hidden & visibility) != 0) {
m_mediaController.hide(); // A
}
else {
m_mediaController.show(); // B
}
}
});
If I comment out lines A and B everything works perfectly (the "working" video). If lines A and B are not commented out, then when I click the Action Bar does hide, but the navigation bar does not(the "Not Working" video). In a second or two the delayedHide(int delayMillis) method gets call and then the navigation bar does hide (!!). Now, this baffles me because calls the same hide() method and mAnchorView.setSystemUiVisibility(mHideFlags) is called with the same flags value as the first call (obviously)
Related
In a certain activity in my app I am hiding the navigation bar since that activity is full screen. To hide the navigation bar I am using the following code:
private void hideSystemUI() {
// Enables regular immersive mode.
// For "lean back" mode, remove SYSTEM_UI_FLAG_IMMERSIVE.
// Or for "sticky immersive," replace it with SYSTEM_UI_FLAG_IMMERSIVE_STICKY
View decorView = getWindow().getDecorView();
decorView.setSystemUiVisibility(
View.SYSTEM_UI_FLAG_IMMERSIVE
| View.SYSTEM_UI_FLAG_HIDE_NAVIGATION // hide nav bar
| View.SYSTEM_UI_FLAG_FULLSCREEN
);
}
This code works fine until the user swipes up the navigation bar. It then stays there. What I want is that it hides again after 2 seconds or so. Is there a way to achieve this?
I appreciate any help!
You can Use this code:
private FullScreenListener fullScreenListener = new FullScreenListener();
private void initUiFlags() {
int flags = View.SYSTEM_UI_FLAG_VISIBLE;
flags |= View.SYSTEM_UI_FLAG_LAYOUT_STABLE
| View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN
| View.SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION;
View decorView = getWindow().getDecorView();
decorView.setSystemUiVisibility(flags);
decorView.setOnSystemUiVisibilityChangeListener(fullScreenListener);
}
Is there a way to auto hide the status bar?
I've already made the status bar hidden when activity starts and I thought it will automatically disappear after a few seconds or when the user interacts whith something else but it doesn't. And I'm still unable to make it disappear.
Here's my code :
if (Build.VERSION.SDK_INT < 16) {
getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN,
WindowManager.LayoutParams.FLAG_FULLSCREEN);
}
else {
View decorView = getWindow().getDecorView();
int uiOptions = View.SYSTEM_UI_FLAG_FULLSCREEN;
decorView.setSystemUiVisibility(uiOptions);
}
I finally found the solution after reading this page.
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_FULLSCREEN
| View.SYSTEM_UI_FLAG_HIDE_NAVIGATION // hide nav bar
| View.SYSTEM_UI_FLAG_FULLSCREEN // hide status bar
| View.SYSTEM_UI_FLAG_IMMERSIVE_STICKY // hide status bar and nav bar after a short delay, or if the user interacts with the middle of the screen
);
Try using these flags:
getWindow().getDecorView().setSystemUiVisibility(
View.SYSTEM_UI_FLAG_LAYOUT_STABLE
| View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN
| View.SYSTEM_UI_FLAG_FULLSCREEN);
Google has a great write up on it here
Our base activity has a method to make it full screen.
Call this in onCreate after super.onCreate and before setContentView() like this:
#Override
protected void onCreate(#Nullable Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
removeTitleBar();
setContentView(your_layout);
}
this is the method:
protected void removeTitleBar() {
requestWindowFeature(Window.FEATURE_NO_TITLE);
getWindow().requestFeature(Window.FEATURE_ACTION_BAR);
if (getSupportActionBar() != null)
getSupportActionBar().hide();
//Remove notification bar
getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN, WindowManager.LayoutParams.FLAG_FULLSCREEN);
}
This works for any api level as far as we support it. But we do not go as low as api 8 or so.
Sometimes 15, mostly 17+.
Hope this helps.
I was wondering how I could hide the navigation bar in an Android application?
I know how to hide it initially, but as soon as I touch the screen it pops back up. I want to hide it the same way games like Clash of Clans hide it where the only way to make it pop up is by swiping down the notifications or by swiping where the navigation bar should be.
use immersive mode check this Immersive mode
// 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);
}
Here it is in the context of the onCreate method:
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
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);
}
The Android docs have a good explanation of what the different flags do:
Using Immersive Full-Screen Mode
Just put this method in your activity where you want to hide status bar and navigation bar in sticky mode.
#Override
public void onWindowFocusChanged(boolean hasFocus) {
super.onWindowFocusChanged(hasFocus);
//This is used to hide/show 'Status Bar' & 'System Bar'. Swip bar to get it as visible.
View decorView = getWindow().getDecorView();
if (hasFocus) {
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);
}
}
the easy way is adding this 2 lines after super.onCreate(savedInstanceState);
getWindow().getDecorView().setSystemUiVisibility(View.SYSTEM_UI_FLAG_HIDE_NAVIGATION);
getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN,WindowManager.LayoutParams.FLAG_FULLSCREEN);
You Can Create An Activity With The Snippet Above,And Then Add Another Windows Above The Layout:
LayoutParams layoutParameteres=new LayoutParams(LayoutParams.MATCH_PARENT, LayoutParams.MATCH_PARENT);
v.setLayoutParams(layoutParameteres);
final WindowManager.LayoutParams parameters=new WindowManager.LayoutParams(sizeX, sizeY, WindowManager.LayoutParams.TYPE_PHONE, WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE, PixelFormat.TRANSLUCENT);
parameters.gravity=Gravity.CENTER;
parameters.x=0;
parameters.y=0;
wm.addView(v, parameters);
Good Luck With It
In your activity's onCreate method:
this.getWindow()
.setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN,
WindowManager.LayoutParams.FLAG_FULLSCREEN);
Modify this line in the AndroidManifest.xml file
android:theme="#style/Theme.AppCompat.DayNight.NoActionBar"
I am working on an application where I have to hide the bottom Navigation Panel. I have search and implement the code :
private void hideSystemUI() {
View mDecorView =getWindow().getDecorView();
// 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_STICKY);
}
This is working fine.
Problem : When I open any DAILOG on the screen or when the keyboard pops up, the bottom NAVIGATION PANEL pops up again.
Please suggest, how can I handle this problem.
this works,
public void FullScreencall() {
if(Build.VERSION.SDK_INT < 19) //19 or above api
View v = this.getWindow().getDecorView();
v.setSystemUiVisibility(View.GONE);
} else {
//for lower api versions.
View decorView = getWindow().getDecorView();
int uiOptions = View.SYSTEM_UI_FLAG_HIDE_NAVIGATION | View.SYSTEM_UI_FLAG_IMMERSIVE_STICKY;
decorView.setSystemUiVisibility(uiOptions);
}
}
call this method on ur oncreat.
Just it, I have found how to hide title bar but I didnt find how hide / show the status bar pressing a button fr example. It is possible? thanks!
For poeple whose show part is not working , You can try following code
Show Status Bar
if (Build.VERSION.SDK_INT < 16) {
getWindow().clearFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN);
}
else {
View decorView = getWindow().getDecorView();
// show the status bar.
int uiOptions = View.SYSTEM_UI_FLAG_VISIBLE;
decorView.setSystemUiVisibility(uiOptions);
}
To hide a status Bar
Use this code in your Activity
getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN,
WindowManager.LayoutParams.FLAG_FULLSCREEN);
Change Application theme in Manifest file as below
android:theme="#android:style/Theme.Black.NoTitleBar"
Reference - https://developer.android.com/training/system-ui/immersive.html
// 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);
}
Although action bar is overlayed with the status bar.