Android Question SLIGHTLY change existing color.

MrKim

Well-Known Member
Licensed User
Longtime User
I have a list of edittexts. I allow the user to select the color of each edittext.
When the user selects a given one I would like to make the color of the selected item a little lighter (or darker) to indicate it is the selected item.

Is there some formula that can help me select the right color? I cannot change the Alpha.

Thanks
 

derez

Expert
Licensed User
Longtime User
A simple way is to add or subtract a little of each of the R,G,B of the color but you can't do that if they are at max (255) or min (0).
Alternatively you can use my class colorpalette https://www.b4x.com/android/forum/threads/colorpalette-and-circularpalette.32483/
To get the RGB from the selected color (if you have it as an Int) use ParseColor.
Use the method ColorToHSL, add or reduce the L (luminosity, lightness) to make the color brighter or darker, and then go back to RGB using HSLToRGB method.




upload_2018-1-21_8-8-41.png
 
Upvote 0

MrKim

Well-Known Member
Licensed User
Longtime User
A simple way is to add or subtract a little of each of the R,G,B of the color but you can't do that if they are at max (255) or min (0).
Alternatively you can use my class colorpalette https://www.b4x.com/android/forum/threads/colorpalette-and-circularpalette.32483/
To get the RGB from the selected color (if you have it as an Int) use ParseColor.
Use the method ColorToHSL, add or reduce the L (luminosity, lightness) to make the color brighter or darker, and then go back to RGB using HSLToRGB method.




View attachment 63914
Thanks! I will give it a try.
 
Upvote 0

MrKim

Well-Known Member
Licensed User
Longtime User
A simple way is to add or subtract a little of each of the R,G,B of the color but you can't do that if they are at max (255) or min (0).
Alternatively you can use my class colorpalette https://www.b4x.com/android/forum/threads/colorpalette-and-circularpalette.32483/
To get the RGB from the selected color (if you have it as an Int) use ParseColor.
Use the method ColorToHSL, add or reduce the L (luminosity, lightness) to make the color brighter or darker, and then go back to RGB using HSLToRGB method.




View attachment 63914
Just a follow up. Thanks again. I wasn't able to just slightly adjust the color using your tool. Some colors were amenable and some were not. Since I am using a finite number of colors (about 30) I did use your tools ColorToHSL and HSLToRGB to help me get close and manually play with the colors, and then used a SELECT CASE statement to set each one.
Thanks for your help.
 
Upvote 0
Top