Paint#setColor does *not* take a resource ID. It takes the RGB color value 
as an int.

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

This is precisely the reason that lint check was added. There are several 
setColor methods that take an integer where the integer is not a resource 
ID - rather it is an int representing the color.

On Friday, 13 February 2015 06:21:41 UTC+5:30, Jason Atwood wrote:
>
> I see back in 2012 a Lint check was added 
> (*http://tools.android.com/recent/newlintrules-1 
> <http://tools.android.com/recent/newlintrules-1>)*
>
>    - Find calls to setColor methods which pass the resource id for the 
>    color (R.color.blue) instead of a resolved color 
>    (getResources().getColor(R.color.blue)).
>    
> Can anybody remember why? There are several setColor methods that gladly 
> take in a resource ID? Paint.setColor() comes to mind:
>
> https://developer.android.com/reference/android/graphics/Paint.html#setColor(int)
>
> Also if you wrote your own setColor method and properly annotated it to 
> take in a color resource you are SOL:
>
> private void setColorId(@ColorRes int color) {
>         someTextView.setTextColor(getResources().getColor(color));
> }
>

-- 
You received this message because you are subscribed to the Google Groups 
"adt-dev" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to adt-dev+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to