My code
paint.setColor(0xFFFFFFFF);
was successfully running before upgrading to Android 10. Now it throws an error:
Wrapped java.lang.IllegalArgumentException: Invalid ID, must be in the range [0..16)
(Looks like the error message is trimmed)
Nevertheless,
paint.setARGB(255,255,255,255);
works fine.
I've read that starting API 29, setColor also accepts long color values, I tried explicitly putting
paint.setColor(parseInt(0xFFFFFFFF));
or
paint.setColor(valueOf(0xFFFFFFFF));
but none of them worked...
Any solutions in how to use setColor? ARGB doesn't always work for me (e.g. cannot create gradient by specifying ARGB).
You can fix this with a cast:
paint.setColor((int)0xFFFFFFFF);
...although I'm unable to reproduce this behavior on my own machine... 0xFFFFFFFF is always interpreted as an int
(even though it's out of range, strictly speaking). Not sure why your compiler is choosing the setColor(long)
override.
Maybe you should try this.
paint.setColor(ContextCompat.getColor(YourActivity.this,R.color.colorPrimary));
Parameter value is treated as long number so it cant calculate the color space. There are two different functions, valueOf(int) and valueOf(long). Just cast to int to get working with standard int value.
valueOf(0xFFFFFFFF.toInt())
User contributions licensed under CC BY-SA 3.0