嗨,我正在尝试将属性从主题传递给代码,但它不起作用。
这是我的代码
样式.xml
<style name="Theme.custom">
<item name="skin">custom</item>
</style>
显现:
<application
android:theme="@style/Theme.custom" >
...
</application>
属性:
<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"
}
}
但!!!!
皮肤按钮将皮肤解析为“自定义” SkinImageView 将皮肤解析为“新:”。我已经搜索过整个项目中没有“新”
有什么帮助吗?