在attrs.xml文件中如下定义:
theme.xml 中如下声明:
layout/xxxx.xml下使用,
这部分代码中要是要使用到自己定义的属性需要如下解析:
改为如下代码 需要请教:
[color=blue]如果哪位仁兄有办法,请予以回复!谢谢![/color]
<?xml version="1.0" encoding="utf-8"?>
<resources>
<declare-styleable name="MyView">
<attr name="textColor" format="color" />
<attr name="textSize" format="dimension" />
<attr name="imgBackground" format="integer" />
<attr name="textPaddingLeft" format="dimension"/>
<attr name="textPaddingRight" format="dimension"/>
<!-- Default TestView style. -->
<attr name="testViewStyle" format="reference" />
</declare-styleable>
</resources>
[color=blue][/color]theme.xml 中如下声明:
<resources>
<style name="ddd.OMS" parent="@android:style/Theme">
<item name="testViewStyle">@style/widget.motiontextview</item>
</style>
</resources>
layout/xxxx.xml下使用,
android:layout_marginRight="15px"
android:layout_marginLeft="15px"
style="@style/ddd.OMS"
android:layout_marginBottom="10px"
这部分代码中要是要使用到自己定义的属性需要如下解析:
TypedArray params = context.obtainStyledAttributes(attrs,
R.styleable.MyView);
TypedArray appearance = null;
int ap = params.getResourceId(R.styleable.MyView_testViewStyle, -1);
if (ap != -1) {
appearance = context.obtainStyledAttributes(ap,
R.styleable.MyView
);
}
float textSize = appearance.getDimension(R.styleable.MyView_textSize, 24);
不过以上属性需要都是自己定义的,才可以在第二次产生的appearance中获取到
改为如下代码 需要请教:
style="?attr/testViewStyle"
暂时不知道如何获取!但是可以通过 int resourceId=attrs.getStyleAttribute()获取testViewStyle 的resource ID,但是现在我还不知道如何获取 testViewStyle 的值!
[color=blue]如果哪位仁兄有办法,请予以回复!谢谢![/color]