Convert colorPrimary to colorPrimaryDark (how much darker)
android, java, material-design
Solution
The official Material Color Tool calculates the darkened/brightened colors based on the JS library chroma.js, using the chroma.darken() / chroma.brighten() function, whose algorithm is based on the CIELAB color space.
snippet from the source code on Github
Color.prototype.darken = function(amount=1) {
const me = this;
const lab = me.lab();
lab[0] -= LAB_CONSTANTS.Kn * amount;
return new Color(lab, 'lab').alpha(me.alpha(), true);
}
Material Color Tool simply uses the fallback value of the amount parameter, while the LAB_CONSTANTS.Kn is 18, it subtracts 18 (to darken) / adds 18 (to brighten) to the lightness component L* of the given base color.
Problem
In guidance with Material Design, how much darker should the statusbar be than the actionbar? I have a color set for the actionbar at runtime and have no way of knowing this colour at programming time, so how can I get the correct statusbar colour? I know i can darken a colour using this ``` this.getSupportActionBar().setBackgroundDrawable(new ColorDrawable(colorPrimary)); float[] hsv = new float[3]; Color.colorToHSV(colorPrimary, hsv); hsv[2] *= 0.8f; int colorPrimaryDark = Color.HSVToColor(hsv); if(Build.VERSION.SDK_INT>=21) Chat.this.getWindow().setStatusBarColor(colorPrimaryDark); ``` But I'm not sure how much to darken it