I feel this is a pretty stupid question, but the Android Color class doesn't seem to have a method to get an int from the R, G, B channels from a Color object individually. Can I get the channels somehow like java.awt's Color can?
Asked
Active
Viewed 7,734 times
3 Answers
9
int color = ContextCompat.getColor(context, R.color.someColor);
int red = Color.red(color);
int blue = Color.blue(color);
int green = Color.green(color);
int alpha = Color.alpha(color);

VikasGoyal
- 3,308
- 1
- 22
- 42
-
I don't want the color from a resource file or anything, I just want to get it from a Color object I made programatically. Am I going to have to get the hex somehow and parse it to get the channels? If that's even possible cause from what I can see this class has very little knowledge. – Joel Feb 20 '17 at 04:26
-
how you made the color object then? – VikasGoyal Feb 20 '17 at 04:28
-
I just realized I never tried initializing an android.graphics.Color object, I only had a Color object in a parameter. Is there no equivalent to java's java.awt.Color on android to work with colors programatically? – Joel Feb 20 '17 at 04:37
-
In Android color values is hold as integer. And if you want to do some operation using that Color value then you have a Color class but it is helper class not actual color value container like AWT. – VikasGoyal Feb 20 '17 at 04:51
2
Did you mean
int colorValue=Color.parseColor(#121212);
int red=Color.red(colorValue);
int green=Color.green(colorValue);
int blue=Color.blue(colorValue);

noobEinstien
- 3,147
- 4
- 24
- 42
2
try this:
String myPassedColor = "#ffffff";
int color = Color.parseColor(myPassedColor)
int r = Color.red(color);
int g = Color.green(color);
int b = Color.blue(color);
int a = Color.alpha(color);

Mahpooya
- 529
- 1
- 6
- 18