How To Check If Int Value Is @colorres Or @colorint?
I have a method in which I can pass an int color value fun setTint(color: Int) { } I can pass both R.color.black and Color.BLACK to it . In the method I want to check if it's @C
Solution 1:
Android resource ids are 32-bit numbers while Android colors can be encoded as 32 bit integers or 64 bit longs.
So checking to see if the number is a valid color resource would be my approach first. If it is not a resource then it can be treated as an encoded color.
if(isColorResource(value)) Log.d(TAG,"Found color resource");
else Log.d(TAG,"Found color value");
publicbooleanisColorResource(int value) {
try {
ResourcesCompat.getColor(getResources(), value, null);
returntrue;
} catch (Resources.NotFoundException e) {
returnfalse;
}
}
Post a Comment for "How To Check If Int Value Is @colorres Or @colorint?"