I have a Fragment for taking a picture and I wanted to have it in full screen mode. Until API 30, I used the flags as described in the official docs here. But after upgrading the version of my project to 30, Android Studio tells that the flag are deprecated. So, I searched a lot and find some SO questions like this one here. Following the answers I changed my code to this:
@Suppress("DEPRECATION")
@SuppressLint("ObsoleteSdkInt")
fun setFullscreen(activity: Activity?) {
activity?.let{
when {
/*I added this case below. And the view looks very weird. Why??*/
Build.VERSION.SDK_INT >= 30 -> {
it.window.setDecorFitsSystemWindows(false)
val controller: WindowInsetsController? = it.window.insetsController
controller?.let { insetsController ->
insetsController.hide(WindowInsets.Type.statusBars() or WindowInsets.Type.navigationBars())
insetsController.systemBarsBehavior = WindowInsetsController.BEHAVIOR_SHOW_TRANSIENT_BARS_BY_SWIPE
}
}
/*The code below worked for years. Why they change working stuff?*/
Build.VERSION.SDK_INT > 10 -> {
// 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
it.window.decorView.systemUiVisibility = (
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.
or View.SYSTEM_UI_FLAG_LAYOUT_STABLE
or View.SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION
or View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN
// Hide the nav bar and status bar
or View.SYSTEM_UI_FLAG_HIDE_NAVIGATION
or View.SYSTEM_UI_FLAG_FULLSCREEN
or View.SYSTEM_UI_FLAG_LOW_PROFILE
)
(it as? AppCompatActivity)?.supportActionBar?.hide()
}
else -> {
it.window
.setFlags(
WindowManager.LayoutParams.FLAG_FULLSCREEN,
WindowManager.LayoutParams.FLAG_FULLSCREEN
)
}
}
}
}
In the fragment, I call this method like this:
override fun onCreateView(
inflater: LayoutInflater, container: ViewGroup?,
savedInstanceState: Bundle?
): View? {
// some code ...
// bla bla etc.
setFullscreen(activity)
// .. and so on
}
Here is a demo:
As you can see, the button on top is not reachable for the user and the bottom of the view is also white. I hope someone can help.