There are several ways to define a color in Java. The simplest is to use the color constants defined in the Color class, such as Color.RED and Color.YELLOW. These are very easy to use but they have a limited range. We can only have BLACK, BLUE, CYAN, DKGRAY, GRAY, GREEN, LTGRAY, MAGENTA, RED, TRANSPARENT, WHITE or YELLOW.
They are also quite unusual in two respects. First they are constants rather than variables so they named with all upper case letters. The value of Color.RED cannot change. Secondly, they are class data values rather than object values. There can be no objects of the Color class because there is only one set of colors. For example, a yellow color object would be the same as any other yellow color object. So they are class constants written with the class name and a capitalized value.
There is another way to define colors that gives us a lot more choice but is more difficult to use. This is based on the idea that any color can be constructed from a combination of red, green and blue components. We assign one byte of computer memory to each component. One byte is an 8 bit number that can have 256 different values from 0 to 255. Then we use three of these as a three byte integer number of which the left byte, that is the highest part of the number, is the red component, the next byte is the green component and the last byte is the blue component.
This gives us 16,777,216 colors. For example, we could specify a color by the integer 16,000,000. This is a very high number so it is some shade of red. Similarly, 65,000 would be a shade of green and 250 would be a bright blue. And 16,065,250 would be a mixture of these components.
However, there is an easier and more precise way to use these numbers and that is to specify the three components as separate numbers from 0 to 255. Then 255, 0, 0 is the brightest red, 0, 255, 0 is the brightest green and 0, 0, 255 is the brightest blue. We might also have 255, 255, 255 which is white, 0, 0, 0 which is black and 100, 100, 100 which is gray. Some other examples are, 200, 200, 0 which is yellow, 200, 50, 0 which is orange, and 0, 100, 250 which is greenish blue.
The Color class provides methods that combine these components to make a complete color. It can also add a fourth component to specify the opaqueness or alpha component of the color. An alpha of 0 is totally transparent and a value of 255 is totally opaque with other values giving various degrees of partial transparency in between these extremes.
The methods are again class methods and are
Color.rgb(int red, int green, int blue) and
Color.argb(int alpha, int red, int green, int blue)
They can be used in Paint methods, for example,
paint,setColor(Color.rgb(int red, int green, int blue)) and
paint.setColor(Color.argb(int alpha, int red, int green, int blue))
So we are using a Paint method to run a Color class method to set the painting color. The Color method returns a color value which is then used as the argument in paint.setColor().
In passing, you might like to note that these components are sometimes expressed as hexadecimal numbers, such as ff0000, 00ff00 and 0000ff, but we can use the decimal notation in Android.