0

I'm changing the color of my Toolbar dynamically and I was wondering if I can change the color of the status bar dynamically as well to match the Toolbar. I know this can be done using:

Window window = getWindow();
window.addFlags(WindowManager.LayoutParams.FLAG_DRAWS_SYSTEM_BAR_BACKGROUNDS);
window.setStatusBarColor({Color});

However, what I'm looking for is to get {Color} dynamically based on the Toolbar color via a calculation/conversion instead of knowing what the hex code is for the darker version of the color.

I read the style guide and it states that the primary color (toolbar) should be the 500 color and the primary dark color (status bar) should be the 700 version. I tried converting a few of the different colors to decimal and unless I'm missing something I couldn't find a correlation between the different 500 vs 700 colors. Any help would be appreciated.

Ryan Sayles
  • 3,389
  • 11
  • 56
  • 79
  • 1
    [This](http://stackoverflow.com/questions/4928772/android-color-darker) might be what you want, presuming you know or can get the color of the toolbar. – Jonas Czech Mar 08 '15 at 14:48
  • Check my answer here http://stackoverflow.com/a/40964456/127923 – Ammar Dec 04 '16 at 22:36

1 Answers1

1

If you want to use a darker shade of your color you can do it by changing your color's HSB. So you take the color of the toolbar and change the Saturation and the Value to obtain a darker shade and you should be good.

For a more detailed way of doing that you can read this post: Android change status bar color by converting existing color's HSB

Andrei
  • 51
  • 4