【发布时间】:2013-01-11 07:24:27
【问题描述】:
我正在自定义LayoutInflater.Factory,并且在 onCreateView() 方法中我想获取为当前视图指定的自定义属性。但是我不想为此属性声明样式。如果在此视图的 xml 属性中指定了此参数,我可以使用:
attrs.getAttributeValue(null, attributeName);
如果在 View 的 style 参数中指定它,我什至可以使用:
context.obtainStyledAttributes(attrs, new int[]{R.attr.custom_attribute);
但是,如果在主题中指定了此属性,似乎不可能获得它。任何帮助将不胜感激。
这是我的 xml 资源:
<style name="CustomTheme"
parent="android:Theme.DeviceDefault">
<item name="android:textViewStyle">@style/TextView.Custom</item>
</style>
<style name="TextView.Custom">
<item name="custom_attribute">"blabla"</item>
</style>
附:我知道我应该为自定义属性声明 slyleable 资源,如果我这样做了,它会起作用,但我想确保它是不可能的,因为使用这种方式更简单。
【问题讨论】:
标签: android