Ben Pearson Ben Pearson - 3 months ago 17
Java Question

obtainStyledAttributes annotated with @StyleableRes. Suppress warnings

While looking at the answer here, I was having problems on the line:

TypedArray ta = obtainStyledAttributes(, attrs);

It seems that Android Studio won't let me pass in an int that doesn't come from a
resource without gettings warnings.

It tells me that it expects a resource of type styleable, which I assume means that the code I'm calling has been annotated with the @StyleableRes annotation

Expected resource of type styleable

What would be the best course of action to read the values defined in the{x}? The accepted answer on the linked post works and compiles, but I don't know how to suppress the warning. As there's a warning, is it safe to suppress? If so, how?


I think the correct way to suppress this :


I'm offered this when I press Alt-Enter to bring up fixes for the warning and choose Inspection 'Constant and Resource Type Mismatches' options > Suppress for class (screenshot attached)enter image description here.

It works for me.

It's possible that the ID for this inspection has changed since whatever code you were referencing was written; I looked briefly through the commit logs but couldn't find a reference to it.