我定义了一个自定义组件,展示一张图片和字符串,declare-styleable如下
<declare-styleable name="Function">
<attr name="functionName" format="string"/>
<attr name="functionImage" format="reference"/>
</declare-styleable>
xml中这样使用
<com.my.ndroid.view.Function
android:layout_width="100dp"
android:layout_height="100dp"
app:functionName="功能1"
app:functionImage="@drawable/function_icon_checked" />
在代码中获取到的却是图片的路径
String image = attributes.getString(R.styleable.Function_functionImage);
image = "res/drawable-v24/function_icon_checked.png"
有没有人告诉我这个路劲该怎么变成一个Drawable?