透明状态栏 - 前4.4奇巧 [英] Transparent status bar - before 4.4 KitKat

查看:218
本文介绍了透明状态栏 - 前4.4奇巧的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我知道4.4奇巧(API 19),它可以让状态栏透明。
但对于例如GO桌面等有一个选项,使之透明,
其工作pre奇巧也对我(的Andr​​oid 4.3 JB)也是一样,也对我的4.0 ICS的设备。

I know in 4.4 KitKat (api 19) its possible to make the status bar transparent.
But for example Go Launcher Ex and others have an option to make it transparent,
and its working on pre KitKat also, for me (Android 4.3 JB) too and also on my 4.0 ICS device.

我并不需要root或任何特殊权限去使用它。
下载GO桌面,并自己尝试一下。
对于我来说,也将是确定的,如果我需要的根。

I didn't need root or any special privileges to use it.
Download Go Launcher Ex and try it yourself.
For me it would also be ok if i would need root.

不过,他们是怎么做到的?
我怎样才能让Android的状态栏半透明的pre奇巧的设备?

But how did they do that?
How can I make Android's status bar translucent on pre KitKat devices?

---澄清事情---

---to clarify things---

我不是在谈论操作栏;我的意思是状态栏(通知栏)!

I'm not talking about the Action Bar; I mean the Status Bar (Notification Bar)!

看到这些例子图片:
(注意,这是从我的库存Galaxy Note的3 的Andr​​oid 4.3 GO桌面
(同样的事情适用于我的银河S2 的Andr​​oid 4.0 太)

see these example pictures:
(notice, this is taken from my Stock Galaxy Note 3 with Android 4.3 and Go Launcher Ex)
(same thing works with my Galaxy S2 and Android 4.0 too)

没有透明居留制吧:

启用透明状态栏:
(我想做到这一点的pre 4.4(API 19)设备)

with transparent status bar enabled:
(i want to achieve this on pre 4.4 (API 19) devices)

推荐答案

我发现了如何获得三星和索尼设备的透明状态栏
至少运行的Andr​​oid 4.0。

I discovered how to get a transparent status bar on Samsung and Sony devices
running at least Android 4.0.

要开始了,让我解释为什么它是不可能在大多数设备:
从安卓官方的一面,有没有办法解决,直到奇巧(4.4)。
但是,一些设备制造商如三星和索尼都在增加其专有软件此选项。

To start off let me explain why it isn't possible on most devices:
From the official side of Android, there is no solution until KitKat (4.4).
But some device manufacturers like Samsung and Sony have added this option in their proprietary software.

三星使用自己的皮肤的Andr​​oid版本,叫的TouchWiz,索尼正在使用自己的系统了。
他们有自己的执行查看类与其他 SYSTEM_UI _ 标记,它们允许启用$ P $透明状态栏的p 4.4的设备!

Samsung uses their own skinned version of Android, called TouchWiz, and Sony is using their own system too.
They have a own implementation of the View class with additional SYSTEM_UI_ flags that allow to enable a transparent statusbar on pre 4.4 devices!

不过,以证明这些标志现有的和他们使用反射来访问的唯一途径。
下面是我的解决方案:

But the only way to prove that those flags are existing and to access them is using Reflection.
Here is my solution:

解析View标志:

int ResolveTransparentStatusBarFlag()
{
    String[] libs = getPackageManager().getSystemSharedLibraryNames();
    String reflect = null;

    if (libs == null)
        return 0;

    for (String lib : libs)
    {
        if (lib.equals("touchwiz"))
            reflect = "SYSTEM_UI_FLAG_TRANSPARENT_BACKGROUND";
        else if (lib.startsWith("com.sonyericsson.navigationbar"))
            reflect = "SYSTEM_UI_FLAG_TRANSPARENT";
    }

    if (reflect == null)
        return 0;

    try
    {
        Field field = View.class.getField(reflect);
        if (field.getType() == Integer.TYPE)
            return field.getInt(null);
    }
    catch (Exception e)
    {
    }

    return 0;
}

它适用于 decorView 你的窗口(内部的任何活动):

Apply it on the decorView of your Window (inside any Activity):

void ApplyTransparentStatusBar()
{
    Window window = getWindow();
    if (window != null)
    {
        View decor = window.getDecorView();
        if (decor != null)
            decor.setSystemUiVisibility(ResolveTransparentStatusBarFlag());
    }
}

我觉得有一些已经实施了这样一个标志
也许其他设备制造商 但我只能推测这两头在外(因为我自己的三星和索尼的设备)

I think there are maybe other device manufacturers that have implemented such a flag
but I was only able to figure this two out (because I own a Samsung and a Sony device)

这篇关于透明状态栏 - 前4.4奇巧的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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