0
votes

I want to set the status bar color in Android devices with targetSdkVersion 19 and up. For versions with Lollipop (21) and up, I used this line of code which worked well: getWindow().setStatusBarColor(ContextCompat.getColor(getApplicationContext(), R.color.colorPrimaryDark)); to set the status bar color to colorPrimary of my application. 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)

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. Overall I would want the status bar color to be all colorPrimary instead of fading from black to colorPrimary. Is there any way I can have the status bar to be all colorPrimary for android devices with KitKat downloaded? Or is there a reason why the android KitKat status bar fades from black to the colorPrimary? Either answer would help. Thanks!

1

1 Answers

0
votes

As far as I know it's a feature of Android KitKat. Both status bar and navigation bar are always black on the screen edges.