Skip to content

Commit c71b6cc

Browse files
leticiarossildjcmu
authored andcommitted
An AutoCompleteTextView should be used in the place of a TextInputEditText, along with with a Widget.MaterialComponents.TextInputLayout.(...).ExposedMenuDropdown style. PiperOrigin-RevId: 246343749
1 parent 058dd07 commit c71b6cc

18 files changed

+892
-47
lines changed
Lines changed: 81 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,81 @@
1+
/*
2+
* Copyright 2019 The Android Open Source Project
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* https://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
17+
package io.material.catalog.textfield;
18+
19+
import io.material.catalog.R;
20+
21+
import android.os.Bundle;
22+
import androidx.annotation.LayoutRes;
23+
import androidx.annotation.Nullable;
24+
import com.google.android.material.textfield.TextInputLayout;
25+
import android.view.LayoutInflater;
26+
import android.view.View;
27+
import android.view.ViewGroup;
28+
import android.widget.ArrayAdapter;
29+
import android.widget.AutoCompleteTextView;
30+
31+
/**
32+
* A fragment that displays the filled text field demos with start and end icons and controls for
33+
* the Catalog app.
34+
*/
35+
public class TextFieldExposedDropdownMenuDemoFragment extends TextFieldControllableDemoFragment {
36+
37+
@Override
38+
public void onChangeTextFieldColors(TextInputLayout textfield, int color) {
39+
if (textfield.getBoxBackgroundMode() == TextInputLayout.BOX_BACKGROUND_FILLED) {
40+
textfield.setBoxBackgroundColor(color);
41+
} else {
42+
textfield.setBoxStrokeColor(color);
43+
}
44+
}
45+
46+
@Override
47+
@LayoutRes
48+
public int getTextFieldContent() {
49+
return R.layout.cat_textfield_exposed_dropdown_menu_content;
50+
}
51+
52+
@Override
53+
public View onCreateDemoView(
54+
LayoutInflater layoutInflater, @Nullable ViewGroup viewGroup, @Nullable Bundle bundle) {
55+
View view = super.onCreateDemoView(layoutInflater, viewGroup, bundle);
56+
57+
ArrayAdapter<CharSequence> adapter =
58+
new ArrayAdapter<>(
59+
getContext(),
60+
R.layout.cat_exposed_dropdown_popup_item,
61+
getResources().getStringArray(R.array.cat_textfield_exposed_dropdown_content));
62+
63+
AutoCompleteTextView editTextFilledExposedDropdown =
64+
view.findViewById(R.id.filled_exposed_dropdown);
65+
editTextFilledExposedDropdown.setAdapter(adapter);
66+
67+
AutoCompleteTextView editTextFilledEditableExposedDropdown =
68+
view.findViewById(R.id.filled_exposed_dropdown_editable);
69+
editTextFilledEditableExposedDropdown.setAdapter(adapter);
70+
71+
AutoCompleteTextView editTextOutlinedExposedDropdown =
72+
view.findViewById(R.id.outlined_exposed_dropdown);
73+
editTextOutlinedExposedDropdown.setAdapter(adapter);
74+
75+
AutoCompleteTextView editTextOutlinedEditableExposedDropdown =
76+
view.findViewById(R.id.outlined_exposed_dropdown_editable);
77+
editTextOutlinedEditableExposedDropdown.setAdapter(adapter);
78+
79+
return view;
80+
}
81+
}

catalog/java/io/material/catalog/textfield/TextFieldFragment.java

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -64,17 +64,24 @@ public Fragment createFragment() {
6464
}
6565
});
6666
additionalDemos.add(
67-
new Demo(R.string.cat_textfield_filled_icons_demo_title) {
67+
new Demo(R.string.cat_textfield_outlined_demo_title) {
6868
@Override
6969
public Fragment createFragment() {
70-
return new TextFieldFilledIconsDemoFragment();
70+
return new TextFieldOutlinedDemoFragment();
7171
}
7272
});
7373
additionalDemos.add(
74-
new Demo(R.string.cat_textfield_outlined_demo_title) {
74+
new Demo(R.string.cat_textfield_exposed_dropdown_menu_demo_title) {
7575
@Override
7676
public Fragment createFragment() {
77-
return new TextFieldOutlinedDemoFragment();
77+
return new TextFieldExposedDropdownMenuDemoFragment();
78+
}
79+
});
80+
additionalDemos.add(
81+
new Demo(R.string.cat_textfield_filled_icons_demo_title) {
82+
@Override
83+
public Fragment createFragment() {
84+
return new TextFieldFilledIconsDemoFragment();
7885
}
7986
});
8087
additionalDemos.add(
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
<?xml version="1.0" encoding="utf-8"?>
2+
<!--
3+
Copyright 2019 The Android Open Source Project
4+
5+
Licensed under the Apache License, Version 2.0 (the "License");
6+
you may not use this file except in compliance with the License.
7+
You may obtain a copy of the License at
8+
9+
http://www.apache.org/licenses/LICENSE-2.0
10+
11+
Unless required by applicable law or agreed to in writing, software
12+
distributed under the License is distributed on an "AS IS" BASIS,
13+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14+
See the License for the specific language governing permissions and
15+
limitations under the License.
16+
-->
17+
<TextView xmlns:android="http://schemas.android.com/apk/res/android"
18+
android:layout_width="match_parent"
19+
android:layout_height="wrap_content"
20+
android:padding="16dp"
21+
android:ellipsize="end"
22+
android:maxLines="1"
23+
android:textAppearance="?attr/textAppearanceSubtitle1"/>
Lines changed: 90 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,90 @@
1+
<?xml version="1.0" encoding="utf-8"?>
2+
<!--
3+
~ Copyright 2019 The Android Open Source Project
4+
~
5+
~ Licensed under the Apache License, Version 2.0 (the "License");
6+
~ you may not use this file except in compliance with the License.
7+
~ You may obtain a copy of the License at
8+
~
9+
~ https://www.apache.org/licenses/LICENSE-2.0
10+
~
11+
~ Unless required by applicable law or agreed to in writing, software
12+
~ distributed under the License is distributed on an "AS IS" BASIS,
13+
~ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14+
~ See the License for the specific language governing permissions and
15+
~ limitations under the License.
16+
-->
17+
18+
<LinearLayout
19+
xmlns:android="http://schemas.android.com/apk/res/android"
20+
xmlns:app="http://schemas.android.com/apk/res-auto"
21+
android:layout_width="match_parent"
22+
android:layout_height="wrap_content"
23+
android:orientation="vertical">
24+
25+
26+
<com.google.android.material.textfield.TextInputLayout
27+
style="@style/Widget.MaterialComponents.TextInputLayout.FilledBox.ExposedDropdownMenu"
28+
android:layout_width="match_parent"
29+
android:layout_height="wrap_content"
30+
android:layout_margin="4dp"
31+
android:hint="@string/cat_textfield_label"
32+
app:errorEnabled="true"
33+
app:helperText="@string/cat_textfield_filled_exposed_dropdown_helper_text"
34+
app:helperTextEnabled="true">
35+
<AutoCompleteTextView
36+
android:id="@+id/filled_exposed_dropdown"
37+
android:layout_width="match_parent"
38+
android:layout_height="wrap_content"
39+
android:editable="false"/>
40+
</com.google.android.material.textfield.TextInputLayout>
41+
42+
43+
<com.google.android.material.textfield.TextInputLayout
44+
style="@style/Widget.MaterialComponents.TextInputLayout.FilledBox.ExposedDropdownMenu"
45+
android:layout_width="match_parent"
46+
android:layout_height="wrap_content"
47+
android:layout_margin="4dp"
48+
android:hint="@string/cat_textfield_label"
49+
app:errorEnabled="true"
50+
app:helperText="@string/cat_textfield_filled_editable_exposed_dropdown_helper_text"
51+
app:helperTextEnabled="true">
52+
<AutoCompleteTextView
53+
android:id="@+id/filled_exposed_dropdown_editable"
54+
android:layout_width="match_parent"
55+
android:layout_height="wrap_content"/>
56+
</com.google.android.material.textfield.TextInputLayout>
57+
58+
<com.google.android.material.textfield.TextInputLayout
59+
style="@style/Widget.MaterialComponents.TextInputLayout.OutlinedBox.ExposedDropdownMenu"
60+
android:layout_width="match_parent"
61+
android:layout_height="wrap_content"
62+
android:layout_margin="4dp"
63+
android:hint="@string/cat_textfield_label"
64+
app:errorEnabled="true"
65+
app:helperText="@string/cat_textfield_outlined_exposed_dropdown_helper_text"
66+
app:helperTextEnabled="true">
67+
<AutoCompleteTextView
68+
android:id="@+id/outlined_exposed_dropdown"
69+
android:layout_width="match_parent"
70+
android:layout_height="wrap_content"
71+
android:editable="false"/>
72+
</com.google.android.material.textfield.TextInputLayout>
73+
74+
75+
<com.google.android.material.textfield.TextInputLayout
76+
style="@style/Widget.MaterialComponents.TextInputLayout.OutlinedBox.ExposedDropdownMenu"
77+
android:layout_width="match_parent"
78+
android:layout_height="wrap_content"
79+
android:layout_margin="4dp"
80+
android:hint="@string/cat_textfield_label"
81+
app:errorEnabled="true"
82+
app:helperText="@string/cat_textfield_outlined_editable_exposed_dropdown_helper_text"
83+
app:helperTextEnabled="true">
84+
<AutoCompleteTextView
85+
android:id="@+id/outlined_exposed_dropdown_editable"
86+
android:layout_width="match_parent"
87+
android:layout_height="wrap_content"/>
88+
</com.google.android.material.textfield.TextInputLayout>
89+
90+
</LinearLayout>

catalog/java/io/material/catalog/textfield/res/values/strings.xml

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
<string name="cat_textfield_title" translatable="false">Text Field</string>
2020
<string name="cat_textfield_filled_demo_title" translatable="false">Filled Text Field Demo</string>
2121
<string name="cat_textfield_filled_icons_demo_title" translatable="false">Filled Icons Text Field Demo</string>
22+
<string name="cat_textfield_exposed_dropdown_menu_demo_title" translatable="false">Exposed Dropdown Menu Demo</string>
2223
<string name="cat_textfield_outlined_demo_title" translatable="false">Outlined Text Field Demo</string>
2324
<string name="cat_textfield_outlined_icons_demo_title" translatable="false">Outlined Icons Text Field Demo</string>
2425
<string name="cat_textfield_legacy_demo_title" translatable="false">Legacy Text Field Demo</string>
@@ -36,6 +37,8 @@
3637
<string name="cat_textfield_filled_start_end_icons_helper_text" translatable="false">Filled start and end icons text field</string>
3738
<string name="cat_textfield_filled_clear_button_helper_text" translatable="false">Filled clear button text field</string>
3839
<string name="cat_textfield_filled_custom_end_icon_helper_text" translatable="false">Filled custom end icon text field</string>
40+
<string name="cat_textfield_filled_exposed_dropdown_helper_text" translatable="false">Filled exposed dropdown menu</string>
41+
<string name="cat_textfield_filled_editable_exposed_dropdown_helper_text" translatable="false">Filled editable exposed dropdown menu</string>
3942
<string name="cat_textfield_legacy_helper_text" translatable="false">Legacy text field</string>
4043
<string name="cat_textfield_outlined_helper_text" translatable="false">Outlined text field</string>
4144
<string name="cat_textfield_outlined_dense_helper_text" translatable="false">Dense outlined text field</string>
@@ -48,6 +51,8 @@
4851
<string name="cat_textfield_outlined_custom_end_icon_helper_text" translatable="false">Outlined custom end icon text field</string>
4952
<string name="cat_textfield_custom_end_icon_content_description" translatable="false">Custom end icon</string>
5053
<string name="cat_textfield_custom_start_icon_content_description" translatable="false">Custom start icon</string>
54+
<string name="cat_textfield_outlined_exposed_dropdown_helper_text" translatable="false">Outlined exposed dropdown menu</string>
55+
<string name="cat_textfield_outlined_editable_exposed_dropdown_helper_text" translatable="false">Outlined editable exposed dropdown menu</string>
5156

5257
<string name="cat_textfield_customize_section_title" translatable="false">Customize text fields</string>
5358
<string name="cat_textfield_customize_section_description" translatable="false">
@@ -70,4 +75,11 @@
7075
<string name="cat_textfield_hide_error_text" translatable="false">Hide error</string>
7176
<string name="cat_textfield_disable" translatable="false">Disable</string>
7277
<string name="cat_textfield_enable" translatable="false">Enable</string>
78+
79+
<string-array name="cat_textfield_exposed_dropdown_content" translatable="false">
80+
<item>Item 1</item>
81+
<item>Item 2</item>
82+
<item>Item 3</item>
83+
<item>Item 4</item>
84+
</string-array>
7385
</resources>

0 commit comments

Comments
 (0)