如何使用xml文件使状态栏和导航栏透明

发布于 2025-01-12 18:26:22 字数 683 浏览 4 评论 0原文

我正在做一个项目,需要状态栏和导航栏是透明的。

我已将状态栏设置为透明,但无法对导航栏执行相同的操作。

谁能帮我解决这个问题。谢谢

我已经设置了这样的样式:

<style name="AppTheme.ActionBar.Transparent" parent="AppTheme">
    <item name="android:statusBarColor" tools:targetApi="lollipop">@android:color/transparent</item>
    <item name="android:navigationBarColor" tools:targetApi="lollipop">@android:color/transparent</item>
    <item name="android:windowTranslucentStatus">false</item>
    <item name="android:windowTranslucentNavigation">true</item>
</style>

注意:我只是在 style.xml 文件中完成了它,因为我已经有了使用该标志的完整版本

I'm doing a project that needs the status bar and the navigation bar to be transparent.

I have made the status bar transparent but I am not able to do the same with the navigation bar.

Can anyone help me with this problem. thank

I have set a style like this :

<style name="AppTheme.ActionBar.Transparent" parent="AppTheme">
    <item name="android:statusBarColor" tools:targetApi="lollipop">@android:color/transparent</item>
    <item name="android:navigationBarColor" tools:targetApi="lollipop">@android:color/transparent</item>
    <item name="android:windowTranslucentStatus">false</item>
    <item name="android:windowTranslucentNavigation">true</item>
</style>

note:I just did it in the style.xml file because I already have a complete version that uses the flag

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

人疚 2025-01-19 18:26:22

在活动类 onCreate 方法中放置此代码

   if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
        Window window = getWindow();
        window.clearFlags(WindowManager.LayoutParams.FLAG_TRANSLUCENT_STATUS);
        window.addFlags(WindowManager.LayoutParams.FLAG_DRAWS_SYSTEM_BAR_BACKGROUNDS);

        View decorView = window.getDecorView();
        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
            decorView.setSystemUiVisibility(View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN | View.SYSTEM_UI_FLAG_LIGHT_STATUS_BAR);
        } else {
            decorView.setSystemUiVisibility(View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN);
        }
        window.setStatusBarColor(Color.TRANSPARENT);
    }

in activity class onCreate method put this code

   if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
        Window window = getWindow();
        window.clearFlags(WindowManager.LayoutParams.FLAG_TRANSLUCENT_STATUS);
        window.addFlags(WindowManager.LayoutParams.FLAG_DRAWS_SYSTEM_BAR_BACKGROUNDS);

        View decorView = window.getDecorView();
        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
            decorView.setSystemUiVisibility(View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN | View.SYSTEM_UI_FLAG_LIGHT_STATUS_BAR);
        } else {
            decorView.setSystemUiVisibility(View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN);
        }
        window.setStatusBarColor(Color.TRANSPARENT);
    }
不奢求什么 2025-01-19 18:26:22

使用导航或状态栏背景颜色代码 #00000000android:background="?android:attr/selectableItemBackground"
这些可以是透明背景,如按钮等......
希望它能起作用

using navigation or status bar background color code #00000000 or android:background="?android:attr/selectableItemBackground"
these can transparent background like button,etc...
hope it will work

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文