I am trying to get my Xamarin.Forms application to use Android's immersive mode, since I am using a device with small screen, so soft keys and navigation bar is stealing my precious screen real estate.
Since the device I am using features hardware keyboard, I wanted to hide the soft keyboard. Currently I solved this by installing a "Null Input Method" keyboard. The keyboard is still there however, so every time focus is requested on Entry element, the keyboard is "shown". This causes application to exit immersive mode. The same is true when I show an Alert from my forms application.
Ideally I would want my application to stay in immersive mode all the time, at least when focus on Entry is requested (soft keyboard is not "shown" at all or immersive mode is not disabled when keyboard is "shown"). For Alerts I would like the application to reenter immersive mode when Alert is hidden. Currently I solved this by extending the Page class with custom DisplayAlert methos, which toggles immersive mode after DisplayAlert Task is completed.
I did some research and found the following articles:
Immersive mode while using keyboard
Appereantly user managed to solve the issue, so there could be a solution?
https://forums.xamarin.com/discussion/33034/prevent-entry-soft-keyboard-from-showing-on-android
But this solution does not work on Entry elements, and I would like to avoid writing custom renderers for elements.
Is there someone that faced a similiar issue before and managed to solve it?
It's not the best solution but defiantly the most simple for me.
Try this:
final Handler forceImmersive = new Handler();
Runnable runnable = new Runnable() {
#Override
public void run() {
// 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_STICKY
// Set the content to appear under the system bars so that the
// content doesn't resize when the system bars hide and show.
| View.SYSTEM_UI_FLAG_LAYOUT_STABLE
| View.SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION
| View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN
// Hide the nav bar and status bar
| View.SYSTEM_UI_FLAG_HIDE_NAVIGATION
| View.SYSTEM_UI_FLAG_FULLSCREEN);
forceImmersive.postDelayed(this, 1000);
}
};
forceImmersive.postDelayed(runnable, 1000);
Related
Don't close this question since this is very old but i cant find the solution.
I'm new to android. I want to disable the soft keys at the bottom and the status permanently once the user opens my app.
It should not appear even on user interaction.
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);
getWindow().addFlags(WindowManager.LayoutParams.FLAG_LAYOUT_NO_LIMITS);
}
}
This code just hides the navigation bar. But when i swipe from the bottom it appears. This should not happen. Please help.
To come out of my app i will provide a way.
Thanks
Don't close this question since this is very old but i cant find the solution. I'm new to android. I want to disable the soft keys at the bottom and the status permanently once the user opens my app.
It should not appear even on user interaction.
I am pretty sure you cannot disable the navigation bar permanently. Otherwise the user will be stuck with your app forever with no way of getting out of it.
I am creating a lock screen application right now. I have been searching and trying some tricks to do it but still can't find the best approach. My previous approach that I used is to use TYPE_SYSTEM_ERROR. it worked well. it prevents navigation and status bar to get any touches. it also run any other app behind my app, including the power off options dialog.
unfortunately I think this is bad because when the app got freeze or not responding, user can't do anything but force restart his/her phone.
I have been looking and analyze some existing lock screen apps in play store. They use different ways to lock the phone but I found one app that I think I can follow. It makes the nav and status bar overlay the app. nav and status bar still can be clicked but it's all opened behind the lock screen. and when I tried to open the power off dialogs, the NavigationBar still overlay the lock screen.
I changed my app to follow that approach. I am able to make the bars overlay my lock screen but I am still not able to:
1. make other app run behind my lock screen (lock screen always on top)
2. the NavigationBar stays overlay when power off dialog appear and when user move to home as well. in my case, the NavigationBar pushed up the screen and my screen looks ugly (some components move to wrong place) and after the Dialog dismissed, it doesn't move back to original position. it's fixed but I noticed a similar problem when I touch the home button and still searching to fix this.
Here's a snippet of my codes (updated):
params = new WindowManager.LayoutParams(
WindowManager.LayoutParams.MATCH_PARENT,
WindowManager.LayoutParams.MATCH_PARENT,
WindowManager.LayoutParams.TYPE_PHONE,
WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE,
PixelFormat.TRANSLUCENT);
params.gravity = Gravity.TOP;
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
getWindow().addFlags(WindowManager.LayoutParams.FLAG_DRAWS_SYSTEM_BAR_BACKGROUNDS);
} else {
getWindow().addFlags(WindowManager.LayoutParams.FLAG_TRANSLUCENT_STATUS);
}
mOverlay = (RelativeLayout) inflater
.inflate(R.layout.main, (ViewGroup) null);
mOverlay.setFitsSystemWindows(false);
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);
mWindowManager = (WindowManager) context
.getSystemService(Context.WINDOW_SERVICE);
mWindowManager.addView(mOverlay, params);
And here a screenshot of app in PlayStore that I want to follow:
Im developing an android application for a school and i want this application when opened to prevent the user from doing anything on the device except what im offering inside my application, and i mean doing NOTHING else...
so first the Navigation bar should be disabled and hided
i saw this but its for 4.4+ and it doesn't solve the problem because if you swipe the screen you will get the menu back.
(How to hide navigation bar permanently in android activity?)
this doesn't work also(Permanently hide navigation bar on activity) (Is there a way to hide the system/navigation bar in Android ICS)
i also tried to disable navigation bar actions using onKeyDown but it didn't work on all of the keys.
in addition i want to remove the notification bar which make the user access the settings of the device and other things..
and this not working also (Disable the notification panel from being pulled down) as mentioned in this link it doesn't solve it, it just hides it after showing it :S
help would be appreciated,
Thanks.
You can get a kiosk type mode in Android 5.0, using the screen pinning feature mentioned here:
Android 5.0 introduces a new screen pinning API that lets you
temporarily restrict users from leaving your task or being interrupted
by notifications. This could be used, for example, if you are
developing an education app to support high stakes assessment
requirements on Android, or a single-purpose or kiosk application.
Once your app activates screen pinning, users cannot see
notifications, access other apps, or return to the home screen, until
your app exits the mode.
You can lock the device down to be a kiosk. The navigation bar is not hidden, but the home and recents buttons can be removed or disabled depending how you activate the mode. I wrote some information after testing this feature here.
Its possible
To disable the Status NotificationBar:
You need to place a view on top of the notification bar, so that we hijack the touch events to the Status notification bar. Without further ado, here is the code:
mView= new TextView(this);
mView.setText(".........................................................................");
mLP = new WindowManager.LayoutParams(
WindowManager.LayoutParams.MATCH_PARENT,
100,
// Allows the view to be on top of the StatusBar
WindowManager.LayoutParams.TYPE_SYSTEM_ERROR,
// Keeps the button presses from going to the background window
WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE |
// Enables the notification to recieve touch events
WindowManager.LayoutParams.FLAG_NOT_TOUCH_MODAL |
// Draws over status bar
WindowManager.LayoutParams.FLAG_LAYOUT_IN_SCREEN,
PixelFormat.TRANSLUCENT);
mLP.gravity = Gravity.TOP|Gravity.CENTER;
mWindowManager = (WindowManager) getSystemService(WINDOW_SERVICE);
mWindowManager.addView(mView, mLP);
And since you are using the system overlay window, you need the permission:
<uses-permission android:name="android.permission.SYSTEM_OVERLAY_WINDOW" />
Note:
Do not make your app full screen, as the versions above 17, which supports immersive mode, will screw this approach.
You can NOT disable the system or notification panel in Android.
You can hide these elements (like you have already discovered), but currently, you can NOT disable them permanently.
You are looking for a 'Kiosk Mode' which is not supported.
The closest thing to what you are looking for is 'Immersive Mode' (details) - but this does NOT hide the settings or navigation controls permanently.
I need to run VideoView in splash kiosk mode.
So I set it to fullscreen (all UI hidden, LOW_PROFILE etc). Mediacontroller not set and not exists. videoview set to not clickable in xml. VideoView OnTouch method overrided. Zorder set to -1. I tried all methods...
but!
Any touch of running VideoView shows me bottom navigation bar (back, home etc) on tablet.
System hides it automatically at 3 seconds. I can not override it :(
How to make VideoView in fullscreen - fully untouchable?
I found a solution, never seen it here.
this totally disables bottom UI on tablet (but leave upper bar on phone)
videoView.setSystemUiVisibility(View.GONE);
to hide status on phone just set in activity onCreate as usual:
super.onCreate(savedInstanceState);
requestWindowFeature(Window.FEATURE_NO_TITLE);
getWindow().addFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN);
getWindow().clearFlags(WindowManager.LayoutParams.FLAG_FORCE_NOT_FULLSCREEN);
getWindow().addFlags(WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON);
setContentView(R.layout.activity_fullscreen);
Have been fighting with this for a while, and it turns out nothing happens if you set the flags on the VideoView, but works when you do it on the mediaController:
mediaController.setSystemUiVisibility(
View.SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION
|View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN
| View.SYSTEM_UI_FLAG_HIDE_NAVIGATION
| View.SYSTEM_UI_FLAG_FULLSCREEN);
A remaining problem is that the video now doesn't seem to respond to touch at all, so the media controls are also gone.
I have a fullscreen activity in which I have some editing area. For Android 4.3 and before, I set fullscreen mode with
activity.getWindow().addFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN);
In the editing view, I use the method described here to get notified when the soft keyboard visibility changes and also to get its height. Everything works fine.
From 4.4, in order to profit immersive mode, the normal mode is set (when status bar is visible) with:
activity.getWindow().getDecorView().setSystemUiVisibility(
View.SYSTEM_UI_FLAG_LAYOUT_STABLE
| View.SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION
| View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN);
But apparently, the method mentioned above to get soft keyboard height is no longer working with getWindowVisibleFrame() returns always the same rectangle whether the keyboard is visible or not.
Here my question: is there any other way to get soft keyboard state and its height on 4.4 that works with SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN?
Thanks in advance.