Add structure for text field demos and split demos into filled and outline demos.

Create base classes for text field demos to unify shared logic and handle optionally controllable text field demos. This new structure is used to split the text field demo into filled and outline controllable demos.

This commit also contains some cleanup for text field demos in general (removes an extra string, converts anonymous listeners to lambdas, etc.)

PiperOrigin-RevId: 196999248
This commit is contained in:
afohrman 2018-05-17 11:55:34 -04:00 committed by Daniel Nizri
parent f23e2eea67
commit 2cf2cfd90e
12 changed files with 499 additions and 309 deletions

View File

@ -19,18 +19,16 @@ package io.material.catalog.textfield;
import io.material.catalog.R;
import android.graphics.Color;
import android.os.Bundle;
import android.support.annotation.Nullable;
import android.support.annotation.LayoutRes;
import com.google.android.material.textfield.TextInputEditText;
import com.google.android.material.textfield.TextInputLayout;
import android.text.TextUtils;
import android.view.LayoutInflater;
import android.view.View;
import android.view.View.OnClickListener;
import android.view.ViewGroup;
import android.widget.Button;
import io.material.catalog.feature.DemoFragment;
/** A fragment that displays the main text field demos for the Catalog app. */
public class TextFieldControllableDemoFragment extends DemoFragment {
/** A base class for controllable text field demos in the Catalog app. */
public abstract class TextFieldControllableDemoFragment extends TextFieldDemoFragment {
private int colorIndex = 0;
private int[] colors =
new int[] {
@ -38,91 +36,80 @@ public class TextFieldControllableDemoFragment extends DemoFragment {
};
@Override
public View onCreateDemoView(
LayoutInflater layoutInflater, @Nullable ViewGroup viewGroup, @Nullable Bundle bundle) {
View view =
layoutInflater.inflate(
R.layout.cat_textfield_controllable_fragment, viewGroup, false /* attachToRoot */);
public void initTextFieldDemoControls(LayoutInflater layoutInflater, View view) {
super.initTextFieldDemoControls(layoutInflater, view);
// Initialize text inputs.
TextInputLayout textInputDemoBoxOutline = view.findViewById(R.id.text_input_demo_box_outline);
TextInputLayout textInputError = view.findViewById(R.id.text_input_error);
TextInputLayout textInputLabel = view.findViewById(R.id.text_input_label);
TextInputLayout textInputCounterMax = view.findViewById(R.id.text_input_counter_max);
// Initialize button for changing the outline box color.
// Initialize button for updating the box color.
Button changeColorButton = view.findViewById(R.id.button_change_color);
changeColorButton.setOnClickListener(
new OnClickListener() {
@Override
public void onClick(View v) {
textInputDemoBoxOutline.setBoxStrokeColor(getNextColor());
}
});
changeColorButton.setOnClickListener(v -> changeTextFieldBoxColors(getNextColor()));
// Initialize button for updating the label text.
TextInputLayout labelTextField = view.findViewById(R.id.text_input_label);
view.findViewById(R.id.button_update_label_text)
.setOnClickListener(
v -> {
if (!checkTextInputIsNull(labelTextField)) {
setAllTextFieldsLabel(String.valueOf(labelTextField.getEditText().getText()));
}
});
// Initialize button for toggling the error text visibility.
Button toggleErrorButton = view.findViewById(R.id.button_toggle_error);
toggleErrorButton.setOnClickListener(
new OnClickListener() {
@Override
public void onClick(View v) {
if (textInputDemoBoxOutline.getError() == null) {
if (textInputError.getEditText().length() == 0) {
textInputDemoBoxOutline.setError(
getResources().getString(R.string.cat_textfield_error));
} else {
textInputDemoBoxOutline.setError(textInputError.getEditText().getText());
}
toggleErrorButton.setText(
getResources().getString(R.string.cat_textfield_hide_error_text));
} else {
textInputDemoBoxOutline.setError(null);
toggleErrorButton.setText(
getResources().getString(R.string.cat_textfield_show_error_text));
}
v -> {
if (!textfields.isEmpty() && textfields.get(0).getError() == null) {
TextInputEditText errorEditText = view.findViewById(R.id.edit_text_error);
String error =
!TextUtils.isEmpty(errorEditText.getText())
? String.valueOf(errorEditText.getText())
: getResources().getString(R.string.cat_textfield_error);
setAllTextFieldsError(error);
toggleErrorButton.setText(
getResources().getString(R.string.cat_textfield_hide_error_text));
} else {
setAllTextFieldsError(null);
toggleErrorButton.setText(
getResources().getString(R.string.cat_textfield_show_error_text));
}
});
// Initialize button for updating the label text.
view.findViewById(R.id.button_update_label_text)
.setOnClickListener(
new OnClickListener() {
@Override
public void onClick(View v) {
if (!checkTextInputIsNull(textInputLabel)) {
textInputDemoBoxOutline.setHint(textInputLabel.getEditText().getText());
}
}
});
// Initialize button for updating the error text.
view.findViewById(R.id.button_update_error_text)
.setOnClickListener(
new OnClickListener() {
@Override
public void onClick(View v) {
if (!checkTextInputIsNull(textInputError)) {
textInputDemoBoxOutline.setError(textInputError.getEditText().getText());
toggleErrorButton.setText(
getResources().getString(R.string.cat_textfield_hide_error_text));
}
}
});
// Initialize button for updating the counter max.
TextInputLayout counterMaxTextField = view.findViewById(R.id.text_input_counter_max);
view.findViewById(R.id.button_counter_max)
.setOnClickListener(
new OnClickListener() {
@Override
public void onClick(View v) {
if (!checkTextInputIsNull(textInputCounterMax)) {
textInputDemoBoxOutline.setCounterMaxLength(
Integer.parseInt(textInputCounterMax.getEditText().getText().toString()));
}
v -> {
if (!checkTextInputIsNull(counterMaxTextField)) {
int length =
Integer.parseInt(counterMaxTextField.getEditText().getText().toString());
setAllTextFieldsCounterMax(length);
}
});
return view;
}
private void changeTextFieldBoxColors(int color) {
for (TextInputLayout textfield : textfields) {
onChangeTextFieldBoxColors(textfield, color);
}
}
public abstract void onChangeTextFieldBoxColors(TextInputLayout textfield, int color);
private void setAllTextFieldsLabel(String label) {
for (TextInputLayout textfield : textfields) {
textfield.setHint(label);
}
}
private void setAllTextFieldsError(String error) {
for (TextInputLayout textfield : textfields) {
textfield.setError(error);
}
}
private void setAllTextFieldsCounterMax(int length) {
for (TextInputLayout textfield : textfields) {
textfield.setCounterMaxLength(length);
}
}
private boolean checkTextInputIsNull(TextInputLayout textInputLayout) {
@ -140,4 +127,10 @@ public class TextFieldControllableDemoFragment extends DemoFragment {
colorIndex = (colorIndex + 1) % colors.length;
return colors[colorIndex];
}
@Override
@LayoutRes
public int getTextFieldDemoControlsLayout() {
return R.layout.cat_textfield_controls;
}
}

View File

@ -0,0 +1,86 @@
/*
* Copyright 2018 The Android Open Source Project
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* https://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package io.material.catalog.textfield;
import io.material.catalog.R;
import android.os.Bundle;
import android.support.annotation.LayoutRes;
import android.support.annotation.Nullable;
import com.google.android.material.textfield.TextInputLayout;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import io.material.catalog.feature.DemoFragment;
import io.material.catalog.feature.DemoUtils;
import java.util.List;
/**
* Base class that provides a structure for text field demos with optional controls for the Catalog
* app.
*/
public abstract class TextFieldDemoFragment extends DemoFragment {
protected List<TextInputLayout> textfields;
@Override
public View onCreateDemoView(
LayoutInflater layoutInflater, @Nullable ViewGroup viewGroup, @Nullable Bundle bundle) {
View view =
layoutInflater.inflate(
R.layout.cat_textfield_fragment, viewGroup, false /* attachToRoot */);
initTextFields(layoutInflater, view);
initTextFieldDemoControls(layoutInflater, view);
return view;
}
private void initTextFields(LayoutInflater layoutInflater, View view) {
inflateTextFields(layoutInflater, view.findViewById(R.id.content));
// Add text fields from the content layout before the text fields from the demo controls to
// allow for modifying the demo text fields without modifying the textfields used for the
// demo controls.
addTextFieldsToList(view);
}
private void inflateTextFields(LayoutInflater layoutInflater, ViewGroup content) {
content.addView(layoutInflater.inflate(getTextFieldContent(), content, false));
}
public void initTextFieldDemoControls(LayoutInflater layoutInflater, View view) {
inflateTextFieldDemoControls(layoutInflater, view.findViewById(R.id.content));
}
private void inflateTextFieldDemoControls(LayoutInflater layoutInflater, ViewGroup content) {
@LayoutRes int demoControls = getTextFieldDemoControlsLayout();
if (demoControls != 0) {
content.addView(layoutInflater.inflate(getTextFieldDemoControlsLayout(), content, false));
}
}
private void addTextFieldsToList(View view) {
textfields = DemoUtils.findViewsWithType(view, TextInputLayout.class);
}
@LayoutRes
public int getTextFieldContent() {
return R.layout.cat_textfield_content;
}
@LayoutRes
public int getTextFieldDemoControlsLayout() {
return 0;
}
}

View File

@ -0,0 +1,37 @@
/*
* Copyright 2018 The Android Open Source Project
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* https://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package io.material.catalog.textfield;
import io.material.catalog.R;
import android.support.annotation.LayoutRes;
import com.google.android.material.textfield.TextInputLayout;
/** A fragment that displays the filled text field demos with controls for the Catalog app. */
public class TextFieldFilledDemoFragment extends TextFieldControllableDemoFragment {
@Override
public void onChangeTextFieldBoxColors(TextInputLayout textfield, int color) {
textfield.setBoxBackgroundColor(color);
}
@Override
@LayoutRes
public int getTextFieldContent() {
return R.layout.cat_textfield_filled_content;
}
}

View File

@ -57,10 +57,17 @@ public class TextFieldFragment extends DemoLandingFragment {
public List<Demo> getAdditionalDemos() {
List<Demo> additionalDemos = new ArrayList<>();
additionalDemos.add(
new Demo(R.string.cat_textfield_controllable_demo_title) {
new Demo(R.string.cat_textfield_filled_demo_title) {
@Override
public Fragment createFragment() {
return new TextFieldControllableDemoFragment();
return new TextFieldFilledDemoFragment();
}
});
additionalDemos.add(
new Demo(R.string.cat_textfield_outline_demo_title) {
@Override
public Fragment createFragment() {
return new TextFieldOutlineDemoFragment();
}
});
return additionalDemos;

View File

@ -24,19 +24,19 @@ import android.support.annotation.Nullable;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import io.material.catalog.feature.DemoFragment;
/** A fragment that displays the main text field demos for the Catalog app. */
public class TextFieldMainDemoFragment extends DemoFragment {
public class TextFieldMainDemoFragment extends TextFieldDemoFragment {
@Override
public View onCreateDemoView(
LayoutInflater layoutInflater, @Nullable ViewGroup viewGroup, @Nullable Bundle bundle) {
return layoutInflater.inflate(getTextfieldsContent(), viewGroup, false /* attachToRoot */);
return layoutInflater.inflate(getTextFieldContent(), viewGroup, false /* attachToRoot */);
}
@Override
@LayoutRes
protected int getTextfieldsContent() {
public int getTextFieldContent() {
return R.layout.cat_textfield_content;
}
}

View File

@ -0,0 +1,37 @@
/*
* Copyright 2018 The Android Open Source Project
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* https://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package io.material.catalog.textfield;
import io.material.catalog.R;
import android.support.annotation.LayoutRes;
import com.google.android.material.textfield.TextInputLayout;
/** A fragment that displays the outline text field demos with controls for the Catalog app. */
public class TextFieldOutlineDemoFragment extends TextFieldControllableDemoFragment {
@Override
public void onChangeTextFieldBoxColors(TextInputLayout textfield, int color) {
textfield.setBoxStrokeColor(color);
}
@Override
@LayoutRes
public int getTextFieldContent() {
return R.layout.cat_textfield_outline_content;
}
}

View File

@ -1,219 +0,0 @@
<?xml version="1.0" encoding="utf-8"?>
<!--
~ Copyright 2018 The Android Open Source Project
~
~ Licensed under the Apache License, Version 2.0 (the "License");
~ you may not use this file except in compliance with the License.
~ You may obtain a copy of the License at
~
~ https://www.apache.org/licenses/LICENSE-2.0
~
~ Unless required by applicable law or agreed to in writing, software
~ distributed under the License is distributed on an "AS IS" BASIS,
~ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
~ See the License for the specific language governing permissions and
~ limitations under the License.
-->
<ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="match_parent">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_margin="@dimen/cat_textfield_standard_spacing"
android:orientation="vertical">
<com.google.android.material.textfield.TextInputLayout
android:id="@+id/text_input_demo_box_outline"
style="@style/Widget.MaterialComponents.TextInputLayout.OutlineBox"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:hint="@string/cat_textfield_label"
app:errorEnabled="true"
app:helperText="@string/cat_textfield_outline_helper_text"
app:helperTextEnabled="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_change_color"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginBottom="@dimen/cat_textfield_standard_spacing"
android:layout_gravity="center_horizontal"
android:text="@string/cat_textfield_customize_color"/>
<Button
android:id="@+id/button_toggle_error"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginBottom="@dimen/cat_textfield_standard_spacing"
android:layout_gravity="center_horizontal"
android:text="@string/cat_textfield_show_error_text"/>
<com.google.android.material.textfield.TextInputLayout
android:id="@+id/text_input_demo_box_outline_dense"
style="@style/Widget.MaterialComponents.TextInputLayout.OutlineBox.Dense"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:hint="@string/cat_textfield_label"
app:boxStrokeColor="?attr/colorSecondaryDark"
app:counterEnabled="true"
app:counterMaxLength="10"
app:errorEnabled="true"
app:helperText="@string/cat_textfield_outline_helper_text"
app:helperTextEnabled="true">
<com.google.android.material.textfield.TextInputEditText
android:layout_width="match_parent"
android:layout_height="wrap_content"/>
</com.google.android.material.textfield.TextInputLayout>
<com.google.android.material.textfield.TextInputLayout
android:id="@+id/text_input_demo_box_filled"
style="@style/Widget.MaterialComponents.TextInputLayout.FilledBox"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="@dimen/cat_textfield_standard_spacing"
android:hint="@string/cat_textfield_label"
app:counterEnabled="true"
app:counterMaxLength="10"
app:errorEnabled="true"
app:helperTextEnabled="true">
<com.google.android.material.textfield.TextInputEditText
android:layout_width="match_parent"
android:layout_height="wrap_content"/>
</com.google.android.material.textfield.TextInputLayout>
<com.google.android.material.textfield.TextInputLayout
android:id="@+id/text_input_demo_box_filled_dense"
style="@style/Widget.MaterialComponents.TextInputLayout.FilledBox.Dense"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="@dimen/cat_textfield_standard_spacing"
android:hint="@string/cat_textfield_label"
app:counterEnabled="true"
app:counterMaxLength="10"
app:errorEnabled="true"
app:helperText="@string/cat_textfield_filled_helper_text"
app:helperTextEnabled="true">
<com.google.android.material.textfield.TextInputEditText
android:layout_width="match_parent"
android:layout_height="wrap_content"/>
</com.google.android.material.textfield.TextInputLayout>
<com.google.android.material.textfield.TextInputLayout
android:id="@+id/text_input_demo_box_filled_dense_password"
style="@style/Widget.MaterialComponents.TextInputLayout.FilledBox.Dense"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:hint="@string/cat_textfield_password"
app:helperText="@string/cat_textfield_filled_dense_password_helper_text"
app:helperTextEnabled="true"
app:passwordToggleEnabled="true">
<com.google.android.material.textfield.TextInputEditText
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:inputType="textPassword"/>
</com.google.android.material.textfield.TextInputLayout>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="@dimen/cat_textfield_large_spacing"
android:layout_marginBottom="@dimen/cat_textfield_standard_spacing"
android:text="@string/cat_textfield_demo_section_title"
android:textAppearance="@style/TextAppearance.AppCompat.Title"/>
<com.google.android.material.textfield.TextInputLayout
android:id="@+id/text_input_demo_line"
style="@style/Widget.Design.TextInputLayout"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:hint="@string/cat_textfield_label"
app:counterEnabled="true"
app:counterMaxLength="10"
app:errorEnabled="true"
app:helperTextEnabled="true">
<com.google.android.material.textfield.TextInputEditText
android:layout_width="match_parent"
android:layout_height="wrap_content"/>
</com.google.android.material.textfield.TextInputLayout>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="@dimen/cat_textfield_large_spacing"
android:layout_marginBottom="@dimen/cat_textfield_standard_spacing"
android:text="@string/cat_textfield_customize_section_title"
android:textAppearance="@style/TextAppearance.AppCompat.Title"/>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/cat_textfield_customize_section_description"
android:textAppearance="@style/TextAppearance.AppCompat.Subhead"/>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_margin="@dimen/cat_textfield_standard_spacing"
android:paddingBottom="@dimen/cat_textfield_standard_spacing"
android:orientation="vertical">
<com.google.android.material.textfield.TextInputLayout
android:id="@+id/text_input_label"
style="@style/Widget.Design.TextInputLayout"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:hint="@string/cat_textfield_customize_label_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_label_text"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center_horizontal"
android:text="@string/cat_textfield_update_label_text"/>
<com.google.android.material.textfield.TextInputLayout
android:id="@+id/text_input_error"
style="@style/Widget.Design.TextInputLayout"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:hint="@string/cat_textfield_customize_error_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_error_text"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center_horizontal"
android:text="@string/cat_textfield_update_error_text"/>
<com.google.android.material.textfield.TextInputLayout
android:id="@+id/text_input_counter_max"
style="@style/Widget.Design.TextInputLayout"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:hint="@string/cat_textfield_customize_counter_text"
app:errorEnabled="true">
<com.google.android.material.textfield.TextInputEditText
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:inputType="number"/>
</com.google.android.material.textfield.TextInputLayout>
<Button
android:id="@+id/button_counter_max"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center_horizontal"
android:text="@string/cat_textfield_update_counter_text"/>
</LinearLayout>
</LinearLayout>
</ScrollView>

View File

@ -0,0 +1,117 @@
<?xml version="1.0" encoding="utf-8"?>
<!--
~ Copyright 2018 The Android Open Source Project
~
~ Licensed under the Apache License, Version 2.0 (the "License");
~ you may not use this file except in compliance with the License.
~ You may obtain a copy of the License at
~
~ https://www.apache.org/licenses/LICENSE-2.0
~
~ Unless required by applicable law or agreed to in writing, software
~ distributed under the License is distributed on an "AS IS" BASIS,
~ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
~ See the License for the specific language governing permissions and
~ limitations under the License.
-->
<ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="match_parent">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_margin="@dimen/cat_textfield_standard_spacing"
android:orientation="vertical">
<Button
android:id="@+id/button_toggle_error"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginBottom="@dimen/cat_textfield_standard_spacing"
android:layout_gravity="center_horizontal"
android:text="@string/cat_textfield_show_error_text"/>
<Button
android:id="@+id/button_change_color"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center_horizontal"
android:text="@string/cat_textfield_customize_color"/>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="@dimen/cat_textfield_large_spacing"
android:layout_marginBottom="@dimen/cat_textfield_standard_spacing"
android:text="@string/cat_textfield_customize_section_title"
android:textAppearance="?attr/textAppearanceHeadline5"/>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/cat_textfield_customize_section_description"
android:textAppearance="?attr/textAppearanceSubtitle1"/>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_margin="@dimen/cat_textfield_standard_spacing"
android:paddingBottom="@dimen/cat_textfield_standard_spacing"
android:orientation="vertical">
<com.google.android.material.textfield.TextInputLayout
android:id="@+id/text_input_label"
style="@style/Widget.Design.TextInputLayout"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:hint="@string/cat_textfield_customize_label_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_label_text"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center_horizontal"
android:text="@string/cat_textfield_update_label_text"/>
<com.google.android.material.textfield.TextInputLayout
style="@style/Widget.Design.TextInputLayout"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:hint="@string/cat_textfield_customize_error_text"
app:errorEnabled="true">
<com.google.android.material.textfield.TextInputEditText
android:id="@+id/edit_text_error"
android:layout_width="match_parent"
android:layout_height="wrap_content"/>
</com.google.android.material.textfield.TextInputLayout>
<Button
android:id="@+id/button_update_error_text"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center_horizontal"
android:text="@string/cat_textfield_update_error_text"/>
<com.google.android.material.textfield.TextInputLayout
android:id="@+id/text_input_counter_max"
style="@style/Widget.Design.TextInputLayout"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:hint="@string/cat_textfield_customize_counter_text"
app:errorEnabled="true">
<com.google.android.material.textfield.TextInputEditText
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:inputType="number"/>
</com.google.android.material.textfield.TextInputLayout>
<Button
android:id="@+id/button_counter_max"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center_horizontal"
android:text="@string/cat_textfield_update_counter_text"/>
</LinearLayout>
</LinearLayout>
</ScrollView>

View File

@ -0,0 +1,69 @@
<?xml version="1.0" encoding="utf-8"?>
<!--
~ Copyright 2018 The Android Open Source Project
~
~ Licensed under the Apache License, Version 2.0 (the "License");
~ you may not use this file except in compliance with the License.
~ You may obtain a copy of the License at
~
~ https://www.apache.org/licenses/LICENSE-2.0
~
~ Unless required by applicable law or agreed to in writing, software
~ distributed under the License is distributed on an "AS IS" BASIS,
~ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
~ See the License for the specific language governing permissions and
~ limitations under the License.
-->
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical">
<com.google.android.material.textfield.TextInputLayout
style="@style/Widget.MaterialComponents.TextInputLayout.FilledBox"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:hint="@string/cat_textfield_label"
app:errorEnabled="true"
app:counterEnabled="true"
app:counterMaxLength="10"
app:helperText="@string/cat_textfield_filled_helper_text"
app:helperTextEnabled="true">
<com.google.android.material.textfield.TextInputEditText
android:layout_width="match_parent"
android:layout_height="wrap_content"/>
</com.google.android.material.textfield.TextInputLayout>
<com.google.android.material.textfield.TextInputLayout
style="@style/Widget.MaterialComponents.TextInputLayout.FilledBox.Dense"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:hint="@string/cat_textfield_label"
app:counterEnabled="true"
app:counterMaxLength="10"
app:errorEnabled="true"
app:helperText="@string/cat_textfield_filled_dense_helper_text"
app:helperTextEnabled="true">
<com.google.android.material.textfield.TextInputEditText
android:layout_width="match_parent"
android:layout_height="wrap_content"/>
</com.google.android.material.textfield.TextInputLayout>
<com.google.android.material.textfield.TextInputLayout
android:id="@+id/text_input_demo_box_filled_dense_password"
style="@style/Widget.MaterialComponents.TextInputLayout.FilledBox.Dense"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:hint="@string/cat_textfield_password"
app:errorEnabled="true"
app:helperText="@string/cat_textfield_filled_dense_password_helper_text"
app:helperTextEnabled="true"
app:passwordToggleEnabled="true">
<com.google.android.material.textfield.TextInputEditText
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:inputType="textPassword"/>
</com.google.android.material.textfield.TextInputLayout>
</LinearLayout>

View File

@ -15,6 +15,13 @@
~ limitations under the License.
-->
<ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/content"
android:layout_width="match_parent"
android:layout_height="match_parent"/>
android:layout_height="match_parent">
<LinearLayout
android:id="@+id/content"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_margin="@dimen/cat_textfield_standard_spacing"
android:orientation="vertical">
</LinearLayout>
</ScrollView>

View File

@ -0,0 +1,56 @@
<?xml version="1.0" encoding="utf-8"?>
<!--
~ Copyright 2018 The Android Open Source Project
~
~ Licensed under the Apache License, Version 2.0 (the "License");
~ you may not use this file except in compliance with the License.
~ You may obtain a copy of the License at
~
~ https://www.apache.org/licenses/LICENSE-2.0
~
~ Unless required by applicable law or agreed to in writing, software
~ distributed under the License is distributed on an "AS IS" BASIS,
~ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
~ See the License for the specific language governing permissions and
~ limitations under the License.
-->
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical">
<com.google.android.material.textfield.TextInputLayout
android:id="@+id/text_input_demo_box_outline"
style="@style/Widget.MaterialComponents.TextInputLayout.OutlineBox"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:hint="@string/cat_textfield_label"
app:counterEnabled="true"
app:counterMaxLength="10"
app:errorEnabled="true"
app:helperText="@string/cat_textfield_outline_helper_text"
app:helperTextEnabled="true">
<com.google.android.material.textfield.TextInputEditText
android:layout_width="match_parent"
android:layout_height="wrap_content"/>
</com.google.android.material.textfield.TextInputLayout>
<com.google.android.material.textfield.TextInputLayout
android:id="@+id/text_input_demo_box_outline_dense"
style="@style/Widget.MaterialComponents.TextInputLayout.OutlineBox.Dense"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:hint="@string/cat_textfield_label"
app:counterEnabled="true"
app:counterMaxLength="10"
app:errorEnabled="true"
app:helperText="@string/cat_textfield_outline_dense_helper_text"
app:helperTextEnabled="true">
<com.google.android.material.textfield.TextInputEditText
android:layout_width="match_parent"
android:layout_height="wrap_content"/>
</com.google.android.material.textfield.TextInputLayout>
</LinearLayout>

View File

@ -17,7 +17,8 @@
<resources>
<string name="cat_textfield_title">Text Field</string>
<string name="cat_textfield_controllable_demo_title">Controllable Text Field Demo</string>
<string name="cat_textfield_filled_demo_title">Filled Text Field Demo</string>
<string name="cat_textfield_outline_demo_title">Outline Text Field Demo</string>
<string name="cat_textfield_description">
Text fields allow users to input, edit, and select text. Text fields typically reside in forms
but can appear in other places, like dialog boxes and search.
@ -31,10 +32,9 @@
<string name="cat_textfield_outline_helper_text">Outline text field</string>
<string name="cat_textfield_outline_dense_helper_text">Dense outline text field</string>
<string name="cat_textfield_demo_section_title">Sample text field</string>
<string name="cat_textfield_customize_section_title">Customize sample text field</string>
<string name="cat_textfield_customize_section_title">Customize text fields</string>
<string name="cat_textfield_customize_section_description">
Enter values below to customize the sample text field.
Enter values below to customize the text fields.
</string>
<string name="cat_textfield_label">Label</string>
<string name="cat_textfield_password">Password</string>