Blog Kotlin

[Android & Kotlin] Fullscreen mode Three approaches to full screen display

Video games and galleries are apps which are most popular to display in full screen. Simple full screen may be annoying for the consumer, and three methods are introduced by Google.

Android Studio three.1.4
API 28
Kotlin 1.2.61

Fullscreen

Although fullscreen in code has the limitation that API is over 19 or more, the share beneath API 19 has turn into significantly less. (Lower than 5% at 2018/7)

For instance, if you need to display this image full screen,

girl tomoka 169x300- [Android & Kotlin] Fullscreen mode Three approaches to full screen display

If that is displayed normally, it is going to be this

original- [Android & Kotlin] Fullscreen mode Three approaches to full screen display

You need to disguise the 3 bars to make it full screen.

  • Standing bar
  • Title bar
  • Navigation bar

In accordance to Allow fullscreen mode | Android Builders say there are three approaches, so let's attempt every one.

Lean back

With these two, you possibly can disguise the status bar and navigation bar.

  • SYSTEM_UI_FLAG_FULLSCREEN
  • SYSTEM_UI_FLAG_HIDE_NAVIGATION
    • Cover navigation bar

It’s also possible to faucet the screen to commute from the full screen.
You’ll be able to see the standing of this technique bar through the use of the listener.
setOnSystemUiVisibilityChangeListener

As well as, inheritance of MainActivity is Exercise () so as to remove the title bar here. (I will cover it later.)

MainActivity.kt

I feel it isn’t related a lot, however it is a format.
activity_main.xml

It’s full screen at startup and you may see the log of “The system bars are NOT visible”.
The screen tap modified the log to “The system bars are visible” and the standing bar and navigation bar appeared.

Immersive

Is it to use it when you’re immersive within the recreation (immersive),
SYSTEM_UI_FLAG_IMMERSIVE
When that is used, the screen is swipe down to unlock the full screen.

  • SYSTEM_UI_FLAG_IMMERSIVE
  • SYSTEM_UI_FLAG_FULLSCREEN
  • SYSTEM_UI_FLAG_HIDE_NAVIGATION

MainActivity.kt

Sticky immersive

immersive is annoying when the system bar (status bar or navigation bar) seems, for instance, if you swipe the screen often in a recreation. You need to use SYSTEM_UI_FLAG_IMMERSIVE_STICKY to alleviate this.

In case you do nothing in a semi-transparent state that does not utterly grow to be a system bar, it is going to be restored in a number of seconds.

  • SYSTEM_UI_FLAG_IMMERSIVE_STICKY
  • SYSTEM_UI_FLAG_FULLSCREEN
  • SYSTEM_UI_FLAG_HIDE_NAVIGATION

MainActivity.kt

Fullscreen Mode

It’s your decision to use AppCompatActivity () as an alternative of Activity (). SYSTEM_UI_FLAG_LAYOUT_STABLE
You possibly can erase the title bar through the use of, however there’s a drawback with this alone.

fullscreen 02- [Android & Kotlin] Fullscreen mode Three approaches to full screen display

Area is created within the status bar and navigation bar of the screen. To remove this
SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION
SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN
These are what lays out the view as if the system bar is hidden.

  • SYSTEM_UI_FLAG_IMMERSIVE_STICKY
  • SYSTEM_UI_FLAG_FULLSCREEN
  • SYSTEM_UI_FLAG_HIDE_NAVIGATION
  • SYSTEM_UI_FLAG_LAYOUT_STABLE
  • SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION
  • SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN

You might also need to delay the disguise using onWindowFocusChanged (hasFocus: Boolean) in order that they don’t seem to be disturbed by the Dialog or Pop up menu and so on.
Summarizing these,
MainActivity.kt

You now have a full screen view.

References:
Allow fullscreen mode | Android Builders
Control the system UI visibility | Android Developers

About the author

FreeGames