ViewStub with custom View attributes for the target layout

Is it possible to pass custom attributes through the ViewStub to the root element of the target layout? For instance:

<ViewStub
        android:layout="@layout/custom_view"
        app:customAttr="12345"
        />

Where custom_view.xml:

<blah.CustomView ...>
    ...
</blah.CustomView>

When I try to do this, CustomView.java does not get "app: customAttr" in the AttributeSet.

When I use CustomView directly, without ViewStub

<blah.Custom app:customAttr="12345"/>

The attribute falls into the AttributeSet normally.

But he is no longer lazy.

Any solutions?

Thank you, Yuri.

+3
source share
1 answer

Similarly <include>, only the attributes that the ViewStub allows you to override are layout attributes and which id will have a child view after inflation.

+2

Source: https://habr.com/ru/post/1751563/


All Articles