在attrs.xml文件中如下定义:
<declare-styleable name="MyViewreference">
    <attr name="testViewStyle" format="reference" />
</declare-styleable>   theme.xml 中如下声明:
<resources>  
    <style name="ddd.OMS" parent="@android:style/Theme">  
        <item name="testViewStyle">@style/widget.motiontextview</item>
    </style>     
</resources> 
layout/xxxx.xml下此使用,但是"@style/ddd.OMS" 一直不起作用。难道还有什么别的步骤?
android:layout_marginRight="15px"
android:layout_marginLeft="15px"
style="@style/ddd.OMS"
android:layout_marginBottom="10px"
改为如下代码:
style="?attr/testViewStyle"
也不行,所以请教。我看android提供的文档里面有这中用法,但是我一直实现不成功。

解决方案 »

  1.   

    1. 你的style指定parent是Theme,Theme是系统主题,包含了很多其它属性的,其一般很少直接用在单一的一个View上,通常都是应用在Activity或者Application上的
    2. style的name里面的点是有意思的“ddd.OMS”代表继承自ddd,把点换成其它的试试
    3. 这样设置的自定义style要有对应的控件去解释,要不然也是没用,自定义属性一定要用在自定义控件里面,要不然是没意义的
    4. 使用自定义属性还需要声明名空间的