How to darken a given color (int)

后端 未结 6 2108

I have a function that takes a given color and I would like it to darken the color (reduce its brightness by 20% or so). I can\'t figure out how to do this given just a colo

6条回答
  •  北荒
    北荒 (楼主)
    2020-12-29 22:09

    This way you can select percentage of color and thus fetch a shade darker or a shade lighter

    int  color = ((ColorDrawable)c2.getBackground()).getColor();
    int  colorLighter = color - color * 40/100;
    int  colorDarker = color + color * 40/100;
    

    colorlighter gives us a lighter shade of color from button's background colordarker gives us a darker shade of color from button's background

提交回复
热议问题