且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

格式属性值QUOT;机器人:可绘制"无效

更新时间:2022-02-26 08:53:59

您可以使用格式=整数,在资源ID 提拉的,和 AttributeSet.getDrawable(...)

You can use format="integer", the resource id of the drawable, and AttributeSet.getDrawable(...).

下面是一个例子。

声明的属性,如RES /价值/ attrs.xml整数:

Declare the attribute as integer in res/values/attrs.xml:

<resources>
    <declare-styleable name="MyLayout">
        <attr name="icon" format="integer" />
    </declare-styleable>
</resources>

属性设置为一个可绘制的ID在你的布局:

Set the attribute to a drawable id in your layout:

<se.jog.MyLayout
    android:layout_width="wrap_content"
    android:layout_height="wrap_content" 
    myapp:icon="@drawable/myImage"
/>

获取从属性的绘制在自定义窗口小部件组件类:

Get the drawable from the attribute in your custom widget component class:

ImageView myIcon;
//...
TypedArray a = context.obtainStyledAttributes(attrs, R.styleable.MyLayout);
Drawable drawable = a.getDrawable(R.styleable.MyLayout_icon);
if (drawable != null)
    myIcon.setBackgroundDrawable(drawable);

要查看所有可能的选项检查android SRC这里

To see all options possible check the android src here