Skip to content

Commit 2642ff2

Browse files
leticiarossicketcham
authored andcommitted
Adding support for TextInputLayout start icon. It can be set to be just a drawable or, if a OnClickListener is set to it, a button.
For that reason, users should opt to use the start icon API instead of setting a start/left compound drawable on the text field's edit text. PiperOrigin-RevId: 238984066
1 parent a1f6a72 commit 2642ff2

18 files changed

Lines changed: 628 additions & 115 deletions

File tree

catalog/java/io/material/catalog/textfield/TextFieldFilledDemoFragment.java

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -18,14 +18,10 @@
1818

1919
import io.material.catalog.R;
2020

21-
import android.graphics.drawable.Drawable;
2221
import android.os.Bundle;
2322
import androidx.annotation.LayoutRes;
2423
import androidx.annotation.Nullable;
25-
import com.google.android.material.textfield.TextInputEditText;
2624
import com.google.android.material.textfield.TextInputLayout;
27-
import androidx.core.widget.TextViewCompat;
28-
import androidx.appcompat.content.res.AppCompatResources;
2925
import android.view.LayoutInflater;
3026
import android.view.View;
3127
import android.view.ViewGroup;
@@ -48,11 +44,6 @@ public int getTextFieldContent() {
4844
public View onCreateDemoView(
4945
LayoutInflater layoutInflater, @Nullable ViewGroup viewGroup, @Nullable Bundle bundle) {
5046
View view = super.onCreateDemoView(layoutInflater, viewGroup, bundle);
51-
TextInputEditText startIconEditText = view.findViewById(R.id.edit_text_start_icon);
52-
Drawable startIcon =
53-
AppCompatResources.getDrawable(view.getContext(), R.drawable.ic_search_24px);
54-
TextViewCompat.setCompoundDrawablesRelativeWithIntrinsicBounds(
55-
startIconEditText, startIcon, null, null, null);
5647
return view;
5748
}
5849
}

catalog/java/io/material/catalog/textfield/TextFieldOutlineDemoFragment.java

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -18,14 +18,10 @@
1818

1919
import io.material.catalog.R;
2020

21-
import android.graphics.drawable.Drawable;
2221
import android.os.Bundle;
2322
import androidx.annotation.LayoutRes;
2423
import androidx.annotation.Nullable;
25-
import com.google.android.material.textfield.TextInputEditText;
2624
import com.google.android.material.textfield.TextInputLayout;
27-
import androidx.core.widget.TextViewCompat;
28-
import androidx.appcompat.content.res.AppCompatResources;
2925
import android.view.LayoutInflater;
3026
import android.view.View;
3127
import android.view.ViewGroup;
@@ -48,11 +44,6 @@ public int getTextFieldContent() {
4844
public View onCreateDemoView(
4945
LayoutInflater layoutInflater, @Nullable ViewGroup viewGroup, @Nullable Bundle bundle) {
5046
View view = super.onCreateDemoView(layoutInflater, viewGroup, bundle);
51-
TextInputEditText startIconEditText = view.findViewById(R.id.edit_text_start_icon);
52-
Drawable startIcon =
53-
AppCompatResources.getDrawable(view.getContext(), R.drawable.ic_search_24px);
54-
TextViewCompat.setCompoundDrawablesRelativeWithIntrinsicBounds(
55-
startIconEditText, startIcon, null, null, null);
5647
return view;
5748
}
5849
}

catalog/java/io/material/catalog/textfield/res/layout/cat_textfield_filled_content.xml

Lines changed: 25 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -113,11 +113,32 @@
113113
app:counterMaxLength="10"
114114
app:errorEnabled="true"
115115
app:helperText="@string/cat_textfield_filled_start_icon_helper_text"
116-
app:helperTextEnabled="true">
116+
app:helperTextEnabled="true"
117+
app:startIconDrawable="@drawable/ic_search_24px"
118+
app:startIconContentDescription="@string/cat_textfield_custom_start_icon_content_description">
117119
<com.google.android.material.textfield.TextInputEditText
118-
android:id="@+id/edit_text_start_icon"
119120
android:layout_width="match_parent"
120-
android:layout_height="wrap_content"
121-
android:drawablePadding="8dp"/>
121+
android:layout_height="wrap_content"/>
122+
</com.google.android.material.textfield.TextInputLayout>
123+
124+
<com.google.android.material.textfield.TextInputLayout
125+
style="@style/Widget.MaterialComponents.TextInputLayout.FilledBox"
126+
android:layout_width="match_parent"
127+
android:layout_height="wrap_content"
128+
android:layout_margin="4dp"
129+
android:hint="@string/cat_textfield_label"
130+
app:counterEnabled="true"
131+
app:counterMaxLength="10"
132+
app:errorEnabled="true"
133+
app:helperText="@string/cat_textfield_filled_start_end_icons_helper_text"
134+
app:helperTextEnabled="true"
135+
app:startIconDrawable="@drawable/ic_search_24px"
136+
app:startIconContentDescription="@string/cat_textfield_custom_start_icon_content_description"
137+
app:endIconMode="custom"
138+
app:endIconDrawable="@drawable/ic_accelerator_24px"
139+
app:endIconContentDescription="@string/cat_textfield_custom_end_icon_content_description">
140+
<com.google.android.material.textfield.TextInputEditText
141+
android:layout_width="match_parent"
142+
android:layout_height="wrap_content"/>
122143
</com.google.android.material.textfield.TextInputLayout>
123144
</LinearLayout>

catalog/java/io/material/catalog/textfield/res/layout/cat_textfield_outline_content.xml

Lines changed: 25 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -100,11 +100,33 @@
100100
app:counterMaxLength="10"
101101
app:errorEnabled="true"
102102
app:helperText="@string/cat_textfield_outline_start_icon_helper_text"
103-
app:helperTextEnabled="true">
103+
app:helperTextEnabled="true"
104+
app:startIconDrawable="@drawable/ic_search_24px"
105+
app:startIconContentDescription="@string/cat_textfield_custom_start_icon_content_description">
104106
<com.google.android.material.textfield.TextInputEditText
105107
android:id="@+id/edit_text_start_icon"
106108
android:layout_width="match_parent"
107-
android:layout_height="wrap_content"
108-
android:drawablePadding="8dp"/>
109+
android:layout_height="wrap_content"/>
110+
</com.google.android.material.textfield.TextInputLayout>
111+
112+
<com.google.android.material.textfield.TextInputLayout
113+
style="@style/Widget.MaterialComponents.TextInputLayout.OutlinedBox"
114+
android:layout_width="match_parent"
115+
android:layout_height="wrap_content"
116+
android:layout_margin="4dp"
117+
android:hint="@string/cat_textfield_label"
118+
app:counterEnabled="true"
119+
app:counterMaxLength="10"
120+
app:errorEnabled="true"
121+
app:helperText="@string/cat_textfield_outline_start_end_icons_helper_text"
122+
app:helperTextEnabled="true"
123+
app:startIconDrawable="@drawable/ic_search_24px"
124+
app:startIconContentDescription="@string/cat_textfield_custom_start_icon_content_description"
125+
app:endIconMode="custom"
126+
app:endIconDrawable="@drawable/ic_accelerator_24px"
127+
app:endIconContentDescription="@string/cat_textfield_custom_end_icon_content_description">
128+
<com.google.android.material.textfield.TextInputEditText
129+
android:layout_width="match_parent"
130+
android:layout_height="wrap_content"/>
109131
</com.google.android.material.textfield.TextInputLayout>
110132
</LinearLayout>

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

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,14 +31,17 @@
3131
Dense filled password text field
3232
</string>
3333
<string name="cat_textfield_filled_start_icon_helper_text">Filled start icon text field</string>
34+
<string name="cat_textfield_filled_start_end_icons_helper_text">Filled start and end icons text field</string>
3435
<string name="cat_textfield_filled_clear_button_helper_text">Filled clear button text field</string>
3536
<string name="cat_textfield_filled_custom_end_icon_helper_text">Filled custom end icon text field</string>
3637
<string name="cat_textfield_outline_helper_text">Outline text field</string>
3738
<string name="cat_textfield_outline_dense_helper_text">Dense outline text field</string>
3839
<string name="cat_textfield_outline_start_icon_helper_text">Outline start icon text field</string>
40+
<string name="cat_textfield_outline_start_end_icons_helper_text">Outline start and end icons text field</string>
3941
<string name="cat_textfield_outline_clear_button_helper_text">Outline clear button text field</string>
4042
<string name="cat_textfield_outline_custom_end_icon_helper_text">Outline custom end icon text field</string>
4143
<string name="cat_textfield_custom_end_icon_content_description">Custom end icon</string>
44+
<string name="cat_textfield_custom_start_icon_content_description">Custom start icon</string>
4245

4346
<string name="cat_textfield_customize_section_title">Customize text fields</string>
4447
<string name="cat_textfield_customize_section_description">

0 commit comments

Comments
 (0)