How to generate a dark shade color from primary color and set the status bar color with it? keep in mind that if the color is bright the icons should be dark and vise versa
Asked
Active
Viewed 241 times
0
-
1do you want to setstatusbar color or do you want to generate darker shade of a given color – Suhaib Roomy May 29 '18 at 22:44
-
I want to generate darker shade of a given color but this darker color should follow material guide lines for generating colorPrimaryDark colors – Mohamed Zakaria El-Zoghbi May 30 '18 at 22:27
2 Answers
1
There are no such guidelines for generating colorPrimaryDark. It just has to be a darker shade to the primary color. Here is the code for generating a darker shade of a given color
public static int manipulateColor(int color, float factor) {
int a = Color.alpha(color);
int r = Math.round(Color.red(color) * factor);
int g = Math.round(Color.green(color) * factor);
int b = Math.round(Color.blue(color) * factor);
return Color.argb(a,
Math.min(r,255),
Math.min(g,255),
Math.min(b,255));
}
factor represents how much you want to darken it, pass anything between 0-1

Suhaib Roomy
- 2,501
- 1
- 16
- 22
-1
You can change color of status bar as:-
if (android.os.Build.VERSION.SDK_INT >= 21)
{
getWindow().setStatusBarColor(getResources().getColor(R.color.anycolor));
}

Raj
- 2,997
- 2
- 12
- 30
-
I don't think this is a wrong answer and it should not be down voted. According to the question that was asked it is a right answer. 3 users have given similar type of answer. If you are not satisfied with the answer then there is a problem in asking the question. Moreover now the question is edited. So, according to the previous question this is a suitable answer.. – Raj May 31 '18 at 05:58