1

I'm making custom LayoutInflater.Factory and in onCreateView() method I'd like to obtain custom attribute specified for current view. However I don't want to declare styleable for this attribute. I can get this parameter if it was specified in xml attribute for this View using: attrs.getAttributeValue(null, attributeName);
I can even get it if it was specified in style parameter of the View using: context.obtainStyledAttributes(attrs, new int[]{R.attr.custom_attribute);
However it seems to be impossible to get this attribute if it's specified in theme. Any help would be appreciated.

Here is my xml resouces:

<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>

P.S. I know I should declare slyleable resource for custom attributes, and it works if I do so, but I want to be sure it is not possible otherwise because it is simplier to use this way.

1 Answer 1

1

Turnd out you can get it usig this:

TypedValue value = new TypedValue();
theme.resolveAttribute(android.R.attr.textViewStyle, value, true);
typedArray = theme.obtainStyledAttributes(value.resourceId, new int[] {R.attr.custom_attribute});
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.