属性定义研究--很浅
在attrs.xml文件中如下定义:
<?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]
<resources> <style name="ddd.OMS" parent="@android:style/Theme"> <item name="testViewStyle">@style/widget.motiontextview</item> </style> </resources>
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 的值!