状态栏与Android KitKat版本褪色?

时间:2016-10-17 01:58:40

标签: android android-5.0-lollipop android-4.4-kitkat android-statusbar

我想在Android设备中使用targetSdkVersion 19及更高版本设置状态栏颜色。对于使用Lollipop(21)及更高版本的版本,我使用了这行代码很好的代码:getWindow().setStatusBarColor(ContextCompat.getColor(getApplicationContext(), R.color.colorPrimaryDark));将状态栏颜色设置为我的应用程序的colorPrimary。但是,我注意到当我尝试将此API用于SDK版本19及更低版本时,我需要使用版本21.结果,我调查了它并发现How to change the status bar color in 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));
        }
    }

状态栏颜色已设置,但它从黑色渐变到我预期的colorPrimary。总的来说,我希望状态栏颜色全部为colorPrimary,而不是从黑色渐变到colorPrimary。有没有什么方法可以让状态栏全部colorPrimary用于下载KitKat的Android设备?或者,为什么Android KitKat状态栏从黑色淡化到colorPrimary?答案都有帮助。谢谢!

1 个答案:

答案 0 :(得分:0)

据我所知,这是Android KitKat的一项功能。状态栏和导航栏在屏幕边缘始终为黑色。