Tôi đang cố tạo chế độ xem phức tạp, nhờ đó tôi có thể đặt thuộc tính trong XML và chuyển chúng đến các trẻ trong chế độ xem kết hợp. Trong đoạn mã bên dưới, tôi muốn đặt android:text
và chuyển đến số EditText
.Chuyển các thuộc tính sang chế độ xem trẻ em trong Chế độ xem hợp chất
Điều này có thể thực hiện mà không phải đặt mọi thuộc tính làm thuộc tính tùy chỉnh không?
activity.xml:
<FrameLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"/>
<com.app.CustomLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="child_view_text" />
</FrameLayout>
custom_view.xml:
<merge xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent">
<android.support.design.widget.TextInputLayout
android:id="@+id/textInputLayout"
android:layout_width="match_parent"
android:layout_height="match_parent">
<EditText
android:id="@+id/editText"
android:layout_width="match_parent"
android:layout_height="match_parent" />
</android.support.design.widget.TextInputLayout>
</merge>
CustomView.java:
public ValidationTextInputLayout(Context context, AttributeSet attrs) {
super(context, attrs);
init(context, attrs);
}
private void init(Context context, AttributeSet attrs) {
View v = inflate(context, R.layout.custom_view, this);
mEditText = (EditText) v.findViewById(R.id.editText);
mTextInputLayout = (TextInputLayout) findViewById(R.id.textInputLayout);
}
Điều này không giải quyết được sự cố. Trong một số trường hợp, tôi cần chuyển các thuộc tính tùy chỉnh khác nhau, ví dụ: "app: box_checked = true". – soundsofpolaris