Add helper text customization controls to text field demo.

PiperOrigin-RevId: 206780816
This commit is contained in:
afohrman 2018-07-31 10:08:24 -07:00 committed by gsajith
parent b62cb0d67f
commit a91d87996b
3 changed files with 37 additions and 0 deletions

View File

@ -73,6 +73,17 @@ public abstract class TextFieldControllableDemoFragment extends TextFieldDemoFra
}
});
// Initialize button for updating the helper text.
TextInputLayout helperTextTextField = view.findViewById(R.id.text_input_helper_text);
view.findViewById(R.id.button_update_helper_text)
.setOnClickListener(
v -> {
if (!checkTextInputIsNull(helperTextTextField)) {
setAllTextFieldsHelperText(
String.valueOf(helperTextTextField.getEditText().getText()));
}
});
// Initialize button for updating the counter max.
TextInputLayout counterMaxTextField = view.findViewById(R.id.text_input_counter_max);
view.findViewById(R.id.button_counter_max)
@ -106,6 +117,12 @@ public abstract class TextFieldControllableDemoFragment extends TextFieldDemoFra
}
}
private void setAllTextFieldsHelperText(String helperText) {
for (TextInputLayout textfield : textfields) {
textfield.setHelperText(helperText);
}
}
private void setAllTextFieldsCounterMax(int length) {
for (TextInputLayout textfield : textfields) {
textfield.setCounterMaxLength(length);

View File

@ -94,6 +94,24 @@
android:layout_gravity="center_horizontal"
android:text="@string/cat_textfield_update_error_text"/>
<com.google.android.material.textfield.TextInputLayout
android:id="@+id/text_input_helper_text"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_margin="4dp"
android:hint="@string/cat_textfield_customize_helper_text"
app:errorEnabled="true">
<com.google.android.material.textfield.TextInputEditText
android:layout_width="match_parent"
android:layout_height="wrap_content"/>
</com.google.android.material.textfield.TextInputLayout>
<Button
android:id="@+id/button_update_helper_text"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center_horizontal"
android:text="@string/cat_textfield_update_helper_text"/>
<com.google.android.material.textfield.TextInputLayout
android:id="@+id/text_input_counter_max"
android:layout_width="match_parent"

View File

@ -42,10 +42,12 @@
<string name="cat_textfield_error">Error</string>
<string name="cat_textfield_customize_label_text">Label text</string>
<string name="cat_textfield_customize_error_text">Error text</string>
<string name="cat_textfield_customize_helper_text">Helper text</string>
<string name="cat_textfield_customize_color">Change color</string>
<string name="cat_textfield_customize_counter_text">Character counter max</string>
<string name="cat_textfield_update_label_text">Update label</string>
<string name="cat_textfield_update_error_text">Update error</string>
<string name="cat_textfield_update_helper_text">Update helper</string>
<string name="cat_textfield_update_counter_text">Update character counter</string>
<string name="cat_textfield_null_input_error_text">Enter a value</string>
<string name="cat_textfield_show_error_text">Show error</string>