Search code examples
androidtype-safety

How to distinguish color int from color resource


I am writing a method that take in color as an integer value (e.g. Color.BLACK).

void justDoIt(int color) {}

Had it been a color resource (e.g. R.color.black), I would have used @ColorRes annotation to be explicit about the type of integer.

void justDoIt(@ColorRes int colorResId) {}

Is there a way to do something similar for int color?

TL;DR: How to ensure that an int param is a int color and not a color resource (opposite of @ColorRes)


Solution

  • There is the annotation @ColorInt for this purpose.