简体   繁体   English

带有Android KitKat版本褪色的状态栏?

[英]Status bar with Android KitKat version fading color?

I want to set the status bar color in Android devices with targetSdkVersion 19 and up. 我想在具有targetSdkVersion 19及更高版本的Android设备中设置状态栏颜色。 For versions with Lollipop (21) and up, I used this line of code which worked well: getWindow().setStatusBarColor(ContextCompat.getColor(getApplicationContext(), R.color.colorPrimaryDark)); 对于带有Lollipop(21)或更高版本的版本,我使用了行之有效的以下代码: getWindow().setStatusBarColor(ContextCompat.getColor(getApplicationContext(), R.color.colorPrimaryDark)); to set the status bar color to colorPrimary of my application. 将状态栏颜色colorPrimary为我的应用程序的colorPrimary However, I noticed that when I try to use this API for SDK version 19 and below, I need to be using version 21. As a result, I looked into it and found How to change the status bar color in android which would solve my problem but when I try to use the following code (Taken from the link above) 但是,我注意到当我尝试将这个API用于SDK版本19及以下时,我需要使用版本21。结果,我对其进行了调查,发现如何在android中更改状态栏颜色可以解决我的问题。问题,但是当我尝试使用以下代码时(取自上面的链接)

public static void setTaskBarColored(Activity context) {
        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT)
        {
            Window w = context.getWindow();
            w.setFlags(WindowManager.LayoutParams.FLAG_TRANSLUCENT_STATUS, WindowManager.LayoutParams.FLAG_TRANSLUCENT_STATUS);
            //status bar height
            int statusBarHeight = Utilities.getStatusBarHeight(context);

            View view = new View(context);
            view.setLayoutParams(new FrameLayout.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.WRAP_CONTENT));
            view.getLayoutParams().height = statusBarHeight;
            ((ViewGroup) w.getDecorView()).addView(view);
            view.setBackgroundColor(context.getResources().getColor(R.color.colorPrimaryTaskBar));
        }
    }

The status bar color is set but it kind of fades from the black to the colorPrimary that I expect it to have. 状态栏的颜色已设置,但从黑色逐渐colorPrimary我期望的colorPrimary Overall I would want the status bar color to be all colorPrimary instead of fading from black to colorPrimary . 总的来说,我希望状态栏颜色全部为colorPrimary而不是从black变为colorPrimary Is there any way I can have the status bar to be all colorPrimary for android devices with KitKat downloaded? 对于下载了KitKat的android设备,有什么方法可以让状态栏全部colorPrimary Or is there a reason why the android KitKat status bar fades from black to the colorPrimary? 还是因为Android KitKat状态栏从黑色逐渐变为colorPrimary的原因? Either answer would help. 回答都可以。 Thanks! 谢谢!

As far as I know it's a feature of Android KitKat. 据我所知,这是Android KitKat的功能。 Both status bar and navigation bar are always black on the screen edges. 状态栏和导航栏在屏幕边缘始终都是黑色的。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM