GetStyledAttributes annotated with @StyleableRes. Suppress warnings

When viewing the answer here I had problems on the line:

TypedArray ta = obtainStyledAttributes(R.style.MyCustomStyle, attrs); 

It seems that Android Studio will not allow me to go into an int that does not come from the R.styleable resource without download warnings.

He tells me that he is expecting a resource of type styleable, which I suppose means that the code I call was annotated with @ annotation StyleableRes

Expected resource of type styleable

What would be the best course of action for reading the values โ€‹โ€‹defined in R.style. {x}? The accepted response to linked mail works and compiles, but I donโ€™t know how to suppress the warning. As a warning, is it safe to suppress? If so, how?

+6
source share
2 answers

I think the correct way to suppress this is:

 @SuppressWarnings("ResourceType") 

I am prompted for this when I press Alt-Enter to trigger corrections for the warning, and select Constant and resource type uncertainty check options > Suppress for class (attached screenshot) enter image description here .

This works for me.

It is possible that the identifier for this check has changed because the code you referenced was written; I briefly looked at the commit logs, but could not find a link to it.

+9
source

You can disable warning checking with @SuppressWarnings("ResourceType") for a method that has a problem, or you can simply use //noinspection ResourceType just before this line to avoid checking only on this line of code.

0
source

Source: https://habr.com/ru/post/976719/


All Articles