0

I can hide on screen home and back buttons like this:

@Override protected void onCreate(Bundle savedInstanceState)
    {
        this.getWindow().addFlags(WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON);
        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);)
    }

and same as onResume. But when my app opens the soft keyboard the buttons comes again and doesn't disappear after keyboard closes. I want home and back buttons to be invisible after soft keyboard is hidden. Any help would be appreciated.

  • possible duplicate of [Return to immersive mode after closing the keyboard on Android](http://stackoverflow.com/questions/23456144/return-to-immersive-mode-after-closing-the-keyboard-on-android) – shkschneider Dec 24 '14 at 13:48

1 Answers1

0

May be you can use a workaround solution for that, you can listen to the soft keyboard dismissing and then when dismissed try to set these flags again.

To listen to the keyboard dismissing(got it from here)and then set the flags again, so the complete solution would be :

final View activityRootView = findViewById(R.id.activityRoot);
activityRootView.getViewTreeObserver().addOnGlobalLayoutListener(new OnGlobalLayoutListener() {
    @Override
    public void onGlobalLayout() {
        int heightDiff = activityRootView.getRootView().getHeight() - activityRootView.getHeight();
        if (heightDiff > 100) { // if more than 100 pixels, its probably a keyboard...
                this.getWindow().addFlags(WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON);
                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);)
        }
     }
});
Community
  • 1
  • 1
Muhammed Refaat
  • 8,914
  • 14
  • 83
  • 118