Android grphics UI Color

HI
I am trying to create a calculator app by watching a youtube video. I see “color=Color.White” in the code. I am trying to understand “Color.White” . Is ‘Color’ is Class and ‘White’ is property. If ‘Color’ is a class, then first I have to create instance of it right to use its properties. But I did not see instance created in the code. I think Color is used directly used. Please share the documentation where I can read about it. Thank you

Color is class, White is an object of this class attached as static property inside color class.

Here is implementation of Color class…

public class Color implements Paint, java.io.Serializable {

    /**
     * The color white.  In the default sRGB space.
     */
    public static final Color white     = new Color(255, 255, 255);

    /**
     * The color white.  In the default sRGB space.
     * @since 1.4
     */
    public static final Color WHITE = white;

    /**
     * The color light gray.  In the default sRGB space.
     */
    public static final Color lightGray = new Color(192, 192, 192);

    /**
     * The color light gray.  In the default sRGB space.
     * @since 1.4
     */
    public static final Color LIGHT_GRAY = lightGray;

    /**
     * The color gray.  In the default sRGB space.
     */
    public static final Color gray      = new Color(128, 128, 128);

    /**
     * The color gray.  In the default sRGB space.
     * @since 1.4
     */
    public static final Color GRAY = gray;

   ... etc ...
1 Like

Thank you for reply. Is this a Java class. Can this class be used in compose where I am trying to use Kotlin. Thank you

@knveraraju91 Compose has its own Color implementation based on Kotlin value classes, not one from the previous comment from Android Views.

In the case of Compose, Color is a class, and White is a companion object property. No need to create any instances. Check Kotlin companion object docs for more details

See also the source code of Color.White

1 Like