如何在自定义视图外的任何位置获取样式属性?

时间:2013-06-27 19:00:39

标签: android android-library android-styles

自定义属性非常棒,但所有教程都提到了自定义视图中的用法,其中您已准备好AttributeSet参数。

我的attrs.xml的内容:

<declare-styleable name="StyledDialogs">
   <attr name="sdlDialogStyle" format="reference" />
</declare-styleable>

<declare-styleable name="DialogStyle">
   ...
</declare-styleable>

我正在努力如何在自定义视图之外的任何类中访问这些属性。

1 个答案:

答案 0 :(得分:2)

几个小时后,我找到了一条有效的方法:

final TypedArray a = mContext.getTheme().obtainStyledAttributes(null, R.styleable.DialogStyle, R.attr.sdlDialogStyle, 0);