David Vávra
David Vávra

Reputation: 19149

How to obtain styled attributes anywhere outside custom view?

Custom attributes are great, but all tutorials mention usage in custom views where you have AttributeSet parameter ready.

Contents of my attrs.xml:

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

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

I'm struggling how to access those attributes in any class outside custom view.

Upvotes: 0

Views: 1983

Answers (1)

David V&#225;vra
David V&#225;vra

Reputation: 19149

After a few hours, I have figured out a way which works:

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

Upvotes: 2

Related Questions