Skip to content

Instantly share code, notes, and snippets.

@hwd6190128
Created May 21, 2019 09:35
Show Gist options
  • Save hwd6190128/57f295575a8c6d6bc89f8b2bfc35366c to your computer and use it in GitHub Desktop.
Save hwd6190128/57f295575a8c6d6bc89f8b2bfc35366c to your computer and use it in GitHub Desktop.
// prefer one
private val immersiveRunnable = Runnable {
immersiveMode(this@BaseActivity)
}
companion object {
private const val INITIAL_HIDE_DELAY = 300L
}
override fun onWindowFocusChanged(hasFocus: Boolean) {
super.onWindowFocusChanged(hasFocus)
if (hasFocus) {
handler.postDelayed(immersiveRunnable, BaseActivity.INITIAL_HIDE_DELAY)
} else {
handler.removeCallbacksAndMessages(immersiveRunnable)
}
}
// last resort
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
// ...
window.decorView.setOnSystemUiVisibilityChangeListener {
if (it and View.SYSTEM_UI_FLAG_FULLSCREEN == 0) {
immersiveMode(this@BaseActivity)
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment