棒棒糖上完全透明的状态栏和导航栏 [英] completely transparent status bar and navigation bar on lollipop

查看:26
本文介绍了棒棒糖上完全透明的状态栏和导航栏的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试制作一个安卓启动器.我想实现一个完全透明的状态栏和导航栏,这里是我的主题xml文件.

I'm trying to make an android launcher. I want to achieve a completely transparent status bar and navigation bar, here is my theme xml file.

<resources>
    <style name="Theme" parent="android:Theme.Material.Wallpaper.NoTitleBar">
        <item name="android:statusBarColor">@android:color/transparent</item>
        <item name="android:navigationBarColor">@android:color/transparent</item>
        <item name="android:windowTranslucentStatus">false</item>
        <item name="android:windowTranslucentNavigation">false</item>
    </style>
</resources>

最后两项不起作用,棒棒糖上仍有阴影.

the last two items don't work, there is still a shadow on lollipop.

这是它的样子(注意状态栏和导航栏上实际上有一个阴影):

This is what it looks like(note there is actually a shadow on status bar and navigation bar):

我想要实现的目标(nova 启动器):

what I want to achieve (nova launcher):

如何让状态栏和导航栏透明"而不是半透明"?

how to make the status bar and navigation bar "transparent" instead of "translucent"?

推荐答案

更新

您可以通过在 Window 中设置 FLAG_LAYOUT_NO_LIMITS 标志在 KitKat 和之后以编程方式实现相同的效果.

Update

You can achieve the same effect programmatically on KitKat and afterward by setting the FLAG_LAYOUT_NO_LIMITS flag inside the Window.

if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) {
            Window w = getWindow(); // in Activity's onCreate() for instance
            w.setFlags(WindowManager.LayoutParams.FLAG_LAYOUT_NO_LIMITS, WindowManager.LayoutParams.FLAG_LAYOUT_NO_LIMITS);
        }

如果您为布局设置背景资源(如颜色或图片),您将在下方"看到颜色或图片状态栏.

If you set a background resource (like a color or a picture) to your layout, you will see the color or picture "below" the status bar.

<item name="android:windowDrawsSystemBarBackgrounds">true</item>
<item name="android:statusBarColor">@color/primary_dark</item>


原答案

看起来 android:windowTranslucentStatusandroid:windowTranslucentNavigation 应该是 true 而不是 false


Original Answer

It looks like android:windowTranslucentStatus and android:windowTranslucentNavigation should be true instead of false

<resources>
    <style name="Theme" parent="android:Theme.Material.Wallpaper.NoTitleBar">
        <item name="android:statusBarColor">@android:color/transparent</item>
        <item name="android:navigationBarColor">@android:color/transparent</item>
        <item name="android:windowTranslucentStatus">true</item>
        <item name="android:windowTranslucentNavigation">true</item>
    </style>
</resources>

此外,您的透明活动/容器布局需要此属性集:

Also, your transparent activity / container layout needs this property set:

android:fitsSystemWindows="true"

[来源][1][1]:https://stackoverflow.com/a/29311321/1549700

[Source][1] [1]: https://stackoverflow.com/a/29311321/1549700

这篇关于棒棒糖上完全透明的状态栏和导航栏的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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