从自定义视图属性获取AttrRes参考

问题描述

我有一个采用icon引用的自定义视图,该引用可以设置为@drawable/some_drawable?some_attr

<MyCustomView
    ...
    app:icon="?some_attr" />
<MyCustomView
    ...
    app:icon="@drawable/some_drawable" />

我知道我可以通过context.obtainStyledAttributes(attrs,R.styleable.icon)代码中访问可绘制资源,但是有没有办法在代码中访问属性引用,即上述情况下的R.attr.some_attr

如果@AttrRes int attrResId可以得到一个0的{​​{1}}变量,如果app:icon="@drawable/some_drawable"可以得到一个R.attr.some_attr

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)