I have the following layout - text_input_layout.xml:
<?xml version="1.0" encoding="utf-8"?>
<layout xmlns:android="http://schemas.android.com/apk/res/android">
<data>
<variable name="textType" type="String"/>
</data>
<TextInputLayout
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
app:errorEnabled="true"
android:textColorHint="@color/white"
android:layout_height="wrap_content"
android:layout_width="match_parent">
<android.support.design.widget.TextInputEditText
android:textColor="@color/White"
android:backgroundTint="@color/White"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:maxLines="1"
android:inputType="@{textType}"
android:id="@+id/password" />
</TextInputLayout>
</layout>
I would like to include this layout in another layout but change the inputType to textPassword, textEmail etc depending on the requirement.
<layout xmlns:bind="http://schemas.android.com/apk/res-auto"
xmlns:android="http://schemas.android.com/apk/res/android">
<RelativeLayout
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
>
<include layout="@layout/text_input_layout"
android:layout_height="wrap_content"
android:layout_width="match_parent"
app:textType="textPassword"/>
</RelativeLayout>
</layout>
I tried to use data binding but it does not seem to work. Could someone please help?
Thanks.
Solution
1) Take
textType
asInteger
value.2) Pass
Integer
to<include
tagapp:textType
.You can also pass 1,2,3... without importing
InputType
but that should be validInputType
.