0

As I have specified a hex value for the background colour of my action bar, I'm finding it a bit difficult deciding which hex value to use for the background colour of the status bar. Are there any tools out there that can help find a suitable background colour for the status bar when one specifies a background colour of the action bar?

ActionBar actionBar = getSupportActionBar();
actionBar.setBackgroundDrawable(new ColorDrawable(Color.parseColor("#E32017")));
wbk727
  • 8,017
  • 12
  • 61
  • 125

2 Answers2

2

Set color on StatusBar as nearest of your ActionBar color:

private String actionBarColor = "#AC6363";

Set Background color on ActionBar:

ActionBar bar = getActionBar();
bar.setBackgroundDrawable(new ColorDrawable(Color.parseColor(actionBarColor)));

To set StatusBar color: on onCreate of Activity:

if (android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.LOLLIPOP) {
    getWindow().setStatusBarColor(getFactorColor(Color.parseColor(actionBarColor), 0.8f));
}

Get factor color:

private int getFactorColor(int color, float factor) {
    float[] hsv = new float[3];
    Color.colorToHSV(color, hsv);
    hsv[2] *= factor;
    color = Color.HSVToColor(hsv);
    return color;
}

Done

Hiren Patel
  • 52,124
  • 21
  • 173
  • 151
0

You can do this only from Lollipop (API level 21) onwards.

if (Build.VERSION.SDK_INT >= 21) {
    getWindow().setStatusBarColor(Color.parseColor("#E32017"));
}
Ahmed Hegazy
  • 12,395
  • 5
  • 41
  • 64
  • Do you know how to solve this with a proper answer and code?[Fast scroll large letter thumb preview not appearing](http://stackoverflow.com/questions/31321784/fast-scroll-large-letter-thumb-preview-not-appearing) – wbk727 Jul 10 '15 at 09:55