Styleable属性未传递给class

时间:2013-07-31 12:02:22

标签: android styles

您好我正在尝试将一个属性从主题传递给代码,但它无法正常工作。

这是我的代码

styles.xml

<style name="Theme.custom">
    <item name="skin">custom</item>
</style>

清单:

<application
    android:theme="@style/Theme.custom" >
...
</application>

ATTRS:

<attr name="skin" format="reference|string" />

<declare-styleable name="SkinImageView">
    <attr name="skin" />
    <attr name="resource" />
</declare-styleable>
<declare-styleable name="SkinButton">
    <attr name="skin" />
    <attr name="resource" />
    <attr name="type" format="reference|string"></attr>
    <attr name="skinButtonStyle" format="reference" />
    <attr name="imageButton" format="boolean" />
    <attr name="android:enabled" />
    <attr name="android:clickable" />
</declare-styleable>

SkinImageView.java

public class SkinImageView extends ImageView {

    protected String skin;

    public SkinImageView(Context context, AttributeSet attrs) {
        super(context, attrs);
        TypedArray array = context.obtainStyledAttributes(attrs,
                R.styleable.SkinImageView);
        String name = array.getString(R.styleable.SkinImageView_resource);
        String sskin = array.getString(R.styleable.SkinImageView_skin);

        array.recycle();

// skin = "NEW:"
    }
}

相同的代码在SkinButton.java

public class SkinButton extends Button {
    private String skin;

    public SkinButton(Context context) {
        this(context, null);
    }

    public SkinButton(Context context, AttributeSet attrs) {
        this(context, attrs, R.attr.skinButtonStyle);
    }

    public SkinButton(Context context, AttributeSet attrs, int defStyle) {
        super(context, attrs, defStyle);
        TypedArray array = context.obtainStyledAttributes(attrs,
                R.styleable.SkinButton, defStyle, R.style.SkinButtonDefault);
        setEnabled(array.getBoolean(R.styleable.SkinButton_android_enabled,
                true));
        setClickable(array.getBoolean(R.styleable.SkinButton_android_clickable,
                true));
        String name = array.getString(R.styleable.SkinButton_resource);
        String type = array.getString(R.styleable.SkinButton_type);
        skin = array.getString(R.styleable.SkinButton_skin);
        array.recycle();

// skin = "custom"
    }
}

BUT !!!!

皮肤按钮将皮肤解析为“自定义”SkinImageView将皮肤解析为“NEW:”。我搜索过整个项目中没有“新”

任何帮助?

0 个答案:

没有答案