Is it possible to apply attributes of one view that is defined via xml to other view that is creating programmatically?
In my case situation is next -
There is custom view FormField:
class FormField extends LinearLayout {
...
@Override
protected void onFinishInflate() {
super.onFinishInflate();
final int childCount = getChildCount();
if (childCount > 1) {
throw new IllegalStateException("FormField can store only one child view");
}
labelView = new TextView(getContext());
addView(labelView, 0);
}
with next target usage:
<com.korovyansk.android.views.FormField
style="@style/Label"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="Field label"
android:layout_marginBottom="300dp"
android:layout_marginRight="16dp"
android:layout_marginLeft="16dp">
<com.korovyansk.android.views.EditText
style="@style/TextField"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:inputType="textCapSentences"
android:imeOptions="actionNext"/>
</com.korovyansk.android.views.FormField>
So the idea is to transfer attributes (style, text, margins) from FormField to TextView created dynamically in onFinishInflated method.