【问题标题】:Status bar with Android KitKat version fading color?Android KitKat 版本褪色的状态栏?
【发布时间】:2016-10-17 01:58:40
【问题描述】:

我想在targetSdkVersion 19 及以上的 Android 设备中设置状态栏颜色。对于 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。对于下载了 KitKat 的 android 设备,有什么办法可以让状态栏全部为 colorPrimary 吗?还是有原因导致 android KitKat 状态栏从黑色变为 colorPrimary?任何一个答案都会有所帮助。谢谢!

【问题讨论】:

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


    【解决方案1】:

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

    【讨论】:

      猜你喜欢
      • 2023-03-12
      • 2016-02-14
      • 2016-10-04
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2020-03-07
      • 2015-08-06
      • 2014-03-18
      相关资源
      最近更新 更多