47
47
import android .widget .ListAdapter ;
48
48
import android .widget .TextView ;
49
49
import androidx .annotation .ArrayRes ;
50
+ import androidx .annotation .ColorInt ;
50
51
import androidx .annotation .LayoutRes ;
51
52
import androidx .annotation .NonNull ;
52
53
import androidx .annotation .Nullable ;
56
57
import com .google .android .material .internal .ManufacturerUtils ;
57
58
import com .google .android .material .internal .ThemeEnforcement ;
58
59
import com .google .android .material .resources .MaterialResources ;
60
+ import com .google .android .material .shape .MaterialShapeDrawable ;
59
61
60
62
/**
61
63
* A special sub-class of {@link android.widget.AutoCompleteTextView} that is auto-inflated so that
@@ -77,6 +79,7 @@ public class MaterialAutoCompleteTextView extends AppCompatAutoCompleteTextView
77
79
@ NonNull private final Rect tempRect = new Rect ();
78
80
@ LayoutRes private final int simpleItemLayout ;
79
81
private final float popupElevation ;
82
+ @ Nullable private ColorStateList dropDownBackgroundTint ;
80
83
private int simpleItemSelectedColor ;
81
84
@ Nullable private ColorStateList simpleItemSelectedRippleColor ;
82
85
@@ -123,6 +126,14 @@ public MaterialAutoCompleteTextView(
123
126
R .styleable .MaterialAutoCompleteTextView_android_popupElevation ,
124
127
R .dimen .mtrl_exposed_dropdown_menu_popup_elevation );
125
128
129
+ if (attributes .hasValue (R .styleable .MaterialAutoCompleteTextView_dropDownBackgroundTint )) {
130
+ dropDownBackgroundTint =
131
+ ColorStateList .valueOf (
132
+ attributes .getColor (
133
+ R .styleable .MaterialAutoCompleteTextView_dropDownBackgroundTint ,
134
+ Color .TRANSPARENT ));
135
+ }
136
+
126
137
simpleItemSelectedColor =
127
138
attributes .getColor (
128
139
R .styleable .MaterialAutoCompleteTextView_simpleItemSelectedColor , Color .TRANSPARENT );
@@ -246,6 +257,54 @@ public void setSimpleItems(@NonNull String[] stringArray) {
246
257
setAdapter (new MaterialArrayAdapter <>(getContext (), simpleItemLayout , stringArray ));
247
258
}
248
259
260
+ /**
261
+ * Sets the color of the popup dropdown container. It will take effect only if the popup
262
+ * background is a {@link MaterialShapeDrawable}, which is the default when using a Material
263
+ * theme.
264
+ *
265
+ * @param dropDownBackgroundColor the popup dropdown container color
266
+ * @see #setDropDownBackgroundTintList(ColorStateList)
267
+ * @see #getDropDownBackgroundTintList()
268
+ * @attr ref
269
+ * com.google.android.material.R.styleable#MaterialAutoCompleteTextView_dropDownBackgroundTint
270
+ */
271
+ public void setDropDownBackgroundTint (@ ColorInt int dropDownBackgroundColor ) {
272
+ setDropDownBackgroundTintList (ColorStateList .valueOf (dropDownBackgroundColor ));
273
+ }
274
+
275
+ /**
276
+ * Sets the color of the popup dropdown container. It will take effect only if the popup
277
+ * background is a {@link MaterialShapeDrawable}, which is the default when using a Material
278
+ * theme.
279
+ *
280
+ * @param dropDownBackgroundTint the popup dropdown container tint as a {@link ColorStateList}
281
+ * object.
282
+ * @see #setDropDownBackgroundTint(int)
283
+ * @see #getDropDownBackgroundTintList()
284
+ * @attr ref
285
+ * com.google.android.material.R.styleable#MaterialAutoCompleteTextView_dropDownBackgroundTint
286
+ */
287
+ public void setDropDownBackgroundTintList (@ Nullable ColorStateList dropDownBackgroundTint ) {
288
+ this .dropDownBackgroundTint = dropDownBackgroundTint ;
289
+ Drawable dropDownBackground = getDropDownBackground ();
290
+ if (dropDownBackground instanceof MaterialShapeDrawable ) {
291
+ ((MaterialShapeDrawable ) dropDownBackground ).setFillColor (this .dropDownBackgroundTint );
292
+ }
293
+ }
294
+
295
+ /**
296
+ * Returns the color of the popup dropdown container.
297
+ *
298
+ * @see #setDropDownBackgroundTint(int)
299
+ * @see #setDropDownBackgroundTintList(ColorStateList)
300
+ * @attr ref
301
+ * com.google.android.material.R.styleable#MaterialAutoCompleteTextView_dropDownBackgroundTint
302
+ */
303
+ @ Nullable
304
+ public ColorStateList getDropDownBackgroundTintList () {
305
+ return dropDownBackgroundTint ;
306
+ }
307
+
249
308
/**
250
309
* Sets the color of the default selected popup dropdown item to be used along with
251
310
* {@code R.attr.simpleItemLayout}.
0 commit comments