Issue
While looking at the answer here, I was having problems on the line:
TypedArray ta = obtainStyledAttributes(R.style.MyCustomStyle, attrs);
It seems that Android Studio won't let me pass in an int that doesn't come from a R.styleable
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
What would be the best course of action to read the values defined in the R.style.{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?
Solution
I think the correct way to suppress this :
@SuppressWarnings("ResourceType")
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).
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.
Answered By - Scott Barta
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.