如何使用Jetpack Compose隐藏ActionBar [英] How to hide ActionBar with Jetpack Compose

查看:28
本文介绍了如何使用Jetpack Compose隐藏ActionBar的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想隐藏默认操作栏,因此在清单文件中有以下代码:

    <style name="Theme.MyCompose" parent="Theme.Material.DayNight.NoActionBar">
</style>

<style name="Theme.Material.DayNight.NoActionBar" parent="@android:style/Theme.Material.Light.NoActionBar" />

效果如下:

我想实现的目标如下:

摄影应覆盖白色区域。如何做到这一点?

更新%1

在实施了半透明状态栏和伴奏插入支持的解决方案后,我遇到了奇怪的行为。当窗口标志设置如下:

 window.setFlags(
        WindowManager.LayoutParams.FLAG_LAYOUT_NO_LIMITS,
        WindowManager.LayoutParams.FLAG_LAYOUT_NO_LIMITS
    )

所有内容看起来都是这样的,尽管插图是打开的:

删除这些标志时,insets起作用,但我有那个影子:

推荐答案

如果需要完全隐藏状态栏,则需要使用全屏主题,如this answer

所示

如果您需要一个透明的状态栏,您可以按照this answer,外加设置Accompanist Insets进行如下操作:

WindowCompat.setDecorFitsSystemWindows(window, false)
window.setFlags(
    WindowManager.LayoutParams.FLAG_LAYOUT_NO_LIMITS,
    WindowManager.LayoutParams.FLAG_LAYOUT_NO_LIMITS
)

然后,您可以在合成中使用systemBarsPadding和其他Accompanist Insets修饰符将图像设置为背景并偏离状态/导航栏。

setContent {
    ProvideWindowInsets {
        ComposePlaygroundTheme {
            Box {
                Image(
                    painterResource(id = R.drawable.my_image),
                    contentDescription = "...",
                    contentScale = ContentScale.FillBounds,
                    modifier = Modifier.fillMaxSize()
                )
                Column(
                    Modifier.systemBarsPadding()
                ) {
                    Button(onClick = { /*TODO*/ }) {
                        Text("Hello")
                    }
                }
            }
        }
    }
}

结果:

这篇关于如何使用Jetpack Compose隐藏ActionBar的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆