Android: Color To Int conversion

前端 未结 5 1154
时光说笑
时光说笑 2020-12-06 03:56

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:

pu         


        
5条回答
  •  眼角桃花
    2020-12-06 04:48

    Paint DOES have set color function.

    /**
     * Set the paint's color. Note that the color is an int containing alpha
     * as well as r,g,b. This 32bit value is not premultiplied, meaning that
     * its alpha can be any value, regardless of the values of r,g,b.
     * See the Color class for more details.
     *
     * @param color The new color (including alpha) to set in the paint.
     */
    public native void setColor(@ColorInt int color);
    

    As an Android developer, I set paint color like this...

    paint.setColor(getResources().getColor(R.color.xxx));
    

    I define the color value on color.xml something like...

    #008fd2
    

    By the way if you want to the hex RGB value of specific color value, then you can check website like this: http://www.rapidtables.com/web/color/RGB_Color.htm

    I hope this helps ! Enjoy coding!

提交回复
热议问题