Android Kotlin: System UI Control

A short code bloc in Kotlin to hide Android devices’ system navigation bar and status bar in order to make a full-screen.

override fun onWindowFocusChanged(hasFocus: Boolean) {
       super.onWindowFocusChanged(hasFocus)
       if (hasFocus) hideSystemUI();
 }
 private fun hideSystemUI(){
       //Hide status bar when keyboard appears
       getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN,
           WindowManager.LayoutParams.FLAG_FULLSCREEN)

       /**Use SYSTEM_UI_FLAG_IMMERSIVE_STICKY to show system UI 
       when scrolling or touching, and to hide the system UI when stopped scrolling*/
       getWindow().getDecorView().systemUiVisibility= 
           (View.SYSTEM_UI_FLAG_IMMERSIVE_STICKY or
            View.SYSTEM_UI_FLAG_LAYOUT_STABLE or 
            View.SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION or 
            View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN or 
            View.SYSTEM_UI_FLAG_HIDE_NAVIGATION or 
            View.SYSTEM_UI_FLAG_FULLSCREEN)
  }

The very similar way and code in Java.

Leave a comment

This site uses Akismet to reduce spam. Learn how your comment data is processed.