I can't get styleable array of attrs

左心房为你撑大大i 提交于 2019-12-10 21:45:43

问题


I am declaring a styleable view with attrs, and I created the file myview_attrs.xml this simple way:

<resources>
    <declare-styleable name="TestStyleable">
        <attr name="testAttr" format="integer"/>
    </declare-styleable>
</resources>

Then, I want to load this attr in my code:

void loadAttributes(AttributeSet attrs) {
    TypedArray typedArray = getContext().obtainStyledAttributes(attrs, R.styleable.);
}

After R.styleable. , with ctrl-SPACE, these are the options I am given:

That is obviously wrong. Indeed, I can't select R.styleable.TestStyleable, because it's not proposed in the menu, but only R.styleable.TestStyleable_testAttr, that does not make sense.

Of course, if I choose the second one it gives me error, because a int[] is expected and I put an int. On the other side, if I manually write R.styleable.TestStyleable fails with "Cannot resolve symbol".

What am I missing here??

Update: this ended to be an Android Studio bug.


回答1:


As @Yurii Tsap stated, this is an Android Studio bug, and it finally got fixed by making

File -> Invalidate Caches / Restart



来源:https://stackoverflow.com/questions/40997845/i-cant-get-styleable-array-of-attrs

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!