2

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?

Denis Vitez
  • 608
  • 11
  • 32

1 Answers1

0

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);
  • Would need to be converted into the right syntax for Xamarin though (i.e c#) as that looks like it's taken from the android documentation and as such is in Java. – JoeTomks May 10 '19 at 12:59