This might be a stupid question but I'm surprised that Paint
class has no setColor(Color c)
method. I want to do the following:
public void setColor(Color color) { /* ... */ Paint p = new Paint(); p.setColor(color); // set color takes only int as a paramter :( /* ... */ }
So any easy way to convert Color
to int
?
The four components of a color int are encoded in the following way: int color = (A & 0xff) << 24 | (R & 0xff) << 16 | (G & 0xff) << 8 | (B & 0xff);
So far I use the following to get the RGB values from it: // rgbs is an array of integers, every single integer represents the // RGB values combined in some way int r = (int) ((Math. pow(256,3) + rgbs[k]) / 65536); int g = (int) (((Math. pow(256,3) + rgbs[k]) / 256 ) % 256 ); int b = (int) ((Math.
Android green is a shade of chartreuse or Caribbean green, defined by Google as the color of the "Android robot" logo for the Android operating system.
Named Color Resources in Android (Note: To add a new resource first select the app in the Project explorer file. Then use the File or context menu, usually right-click, then the New option and select Android resource file. A color resource does not need to be stored in colors. xml, other file names can be used.)
Any color
parse into int
simplest two way here:
1) Get System Color
int redColorValue = Color.RED;
2) Any Color Hex Code as a String Argument
int greenColorValue = Color.parseColor("#00ff00")
MUST REMEMBER in above code Color
class must be android.graphics...
!
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With