Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Android: Color To Int conversion

Tags:

android

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?

like image 879
Caner Avatar asked Aug 03 '11 12:08

Caner


People also ask

How can I change the color of INT in Android?

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);

How do you convert RGB to INT?

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.

What is android color?

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.

How to use color in android?

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.)


1 Answers

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...!

like image 52
Dhruv Raval Avatar answered Oct 03 '22 19:10

Dhruv Raval