自定义属性非常棒,但所有教程都提到了自定义视图中的用法,其中您已准备好AttributeSet参数。
我的attrs.xml的内容:
<declare-styleable name="StyledDialogs">
<attr name="sdlDialogStyle" format="reference" />
</declare-styleable>
<declare-styleable name="DialogStyle">
...
</declare-styleable>
我正在努力如何在自定义视图之外的任何类中访问这些属性。
答案 0 :(得分:2)
几个小时后,我找到了一条有效的方法:
final TypedArray a = mContext.getTheme().obtainStyledAttributes(null, R.styleable.DialogStyle, R.attr.sdlDialogStyle, 0);