admin管理员组文章数量:1277401
I am trying to create a true fullscreen edge-to-edge experience in my Android app using Jetpack Compose. The goal is to remove the status bar, extend my content into the area behind it, and make my app display seamlessly from edge to edge without any black space around the status bar or navigation bar.
See black spacing here where my camera sits.
Here is my activity
class TPMActivity : ComponentActivity() {
private val settingsRepository: SettingsRepository by lazy {
SettingsRepository(applicationContext)
}
private val settingsViewModel: SettingsViewModel by lazy {
SettingsViewModel(settingsRepository)
}
@SuppressLint("UnusedMaterial3ScaffoldPaddingParameter")
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
requestedOrientation = ActivityInfo.SCREEN_ORIENTATION_PORTRAIT
setContent {
if (settings.showSystemUi) {
showSystemUI(this)
} else {
hideSystemUI(this)
}
Scaffold(
content = {
MyContent()
}
)
}
}
}
And here is my utils functions
fun hideSystemUI(activity: Activity) {
WindowCompat.setDecorFitsSystemWindows(activity.window, false)
WindowInsetsControllerCompat(activity.window, activity.window.decorView).let { controller ->
controller.hide(WindowInsetsCompat.Type.systemBars())
controller.systemBarsBehavior = WindowInsetsControllerCompat.BEHAVIOR_SHOW_TRANSIENT_BARS_BY_SWIPE
}
}
fun showSystemUI(activity: Activity) {
WindowCompat.setDecorFitsSystemWindows(activity.window, true)
WindowInsetsControllerCompat(activity.window, activity.window.decorView).let { controller ->
controller.hide(WindowInsetsCompat.Type.statusBars())
controller.show(WindowInsetsCompat.Type.navigationBars())
}
}
本文标签:
版权声明:本文标题:android - How to achieve true fullscreen edge-to-edge in Jetpack Compose without any space for the status bar? - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1741259731a2367380.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论