diff --git a/docs/components/Menu.md b/docs/components/Menu.md
index e6200f1f66a..a4143449eb0 100644
--- a/docs/components/Menu.md
+++ b/docs/components/Menu.md
@@ -562,19 +562,21 @@ The exposed dropdown menu is an `AutoCompleteTextView` within a
For all attributes that apply to the `TextInputLayout`, see the
[TextInputLayout documentation](TextField.md).
-#### `AutoCompleteTextView` attributes (input text, dropdown menu)
-
-Element | Attribute | Related method(s) | Default value
-------------------------------------- | ------------------------------------------------------------------- | ------------------------------------------------------------ | -------------
-**Input text** | `android:text` | `setText`
`getText` | `@null`
-**Typography** | `android:textAppearance` | `setTextAppearance` | `?attr/textAppearanceBodyLarge`
-**Input accepted** | `android:inputType` | `N/A` | framework's default
-**Input text color** | `android:textColor` | `setTextColor`
`getTextColors`
`getCurrentTextColor` | `?android:textColorPrimary`
-**Cursor color** | N/A (color comes from the theme attr `?attr/colorControlActivated`) | N/A | `?attr/colorPrimary`
-**Dropdown menu
container color** | N/A | N/A | `?attr/colorSurface`
-**Dropdown menu elevation** | `android:popupElevation` | `getPopupElevation` | `3dp`
-**Simple items** | `app:simpleItems` | `setSimpleItems` | `null`
-**Simple item layout** | `app:simpleItemLayout` | N/A | `@layout/m3_auto_complete_simple_item`
+#### `MaterialAutoCompleteTextView` attributes (input text, dropdown menu)
+
+Element | Attribute | Related method(s) | Default value
+----------------------------------------- | ------------------------------------------------------------------- | ----------------------------------------------------------------------------- | -------------
+**Input text** | `android:text` | `setText`
`getText` | `@null`
+**Typography** | `android:textAppearance` | `setTextAppearance` | `?attr/textAppearanceBodyLarge`
+**Input accepted** | `android:inputType` | `N/A` | framework's default
+**Input text color** | `android:textColor` | `setTextColor`
`getTextColors`
`getCurrentTextColor` | `?android:textColorPrimary`
+**Cursor color** | N/A (color comes from the theme attr `?attr/colorControlActivated`) | N/A | `?attr/colorPrimary`
+**Dropdown menu
container color** | N/A | N/A | `?attr/colorSurface`
+**Dropdown menu elevation** | `android:popupElevation` | `getPopupElevation` | `3dp`
+**Simple items** | `app:simpleItems` | `setSimpleItems` | `null`
+**Simple item layout** | `app:simpleItemLayout` | N/A | `@layout/m3_auto_complete_simple_item`
+**Selected simple item color** | `app:simpleItemSelectedColor` | `setSimpleItemSelectedColor`
`getSimpleItemSelectedColor` | `?attr/colorSurfaceVariant`
+**Selected simple item
ripple color** | `app:simpleItemSelectedRippleColor` | `setSimpleItemSelectedRippleColor`
`getSimpleItemSelectedRippleColor` | `@color/m3_simple_item_ripple_color`
#### Styles
diff --git a/docs/components/TextField.md b/docs/components/TextField.md
index 43b047097ae..ac1e0f28f65 100644
--- a/docs/components/TextField.md
+++ b/docs/components/TextField.md
@@ -206,7 +206,7 @@ See the full list of
### Implementing an exposed dropdown menu
-!["Text field with an exposed dropdown menu."](assets/textfields/textfields_exposed_dropdown_menu.png)
+!["Text field with an exposed dropdown menu."](assets/menu/menus_exposed_dropdown_outlined.png)
In the layout:
diff --git a/docs/components/assets/menu/menus_exposed_dropdown_filled.png b/docs/components/assets/menu/menus_exposed_dropdown_filled.png
index 7a267d7ba8f..9a5ca8e8528 100644
Binary files a/docs/components/assets/menu/menus_exposed_dropdown_filled.png and b/docs/components/assets/menu/menus_exposed_dropdown_filled.png differ
diff --git a/docs/components/assets/menu/menus_exposed_dropdown_outlined.png b/docs/components/assets/menu/menus_exposed_dropdown_outlined.png
index 1eb025978c2..6c3bb53728a 100644
Binary files a/docs/components/assets/menu/menus_exposed_dropdown_outlined.png and b/docs/components/assets/menu/menus_exposed_dropdown_outlined.png differ
diff --git a/docs/components/assets/textfields/textfields_exposed_dropdown_menu.png b/docs/components/assets/textfields/textfields_exposed_dropdown_menu.png
deleted file mode 100644
index 342cfeb14e0..00000000000
Binary files a/docs/components/assets/textfields/textfields_exposed_dropdown_menu.png and /dev/null differ
diff --git a/lib/java/com/google/android/material/textfield/MaterialAutoCompleteTextView.java b/lib/java/com/google/android/material/textfield/MaterialAutoCompleteTextView.java
index 01ca9650df3..0166a3b7282 100644
--- a/lib/java/com/google/android/material/textfield/MaterialAutoCompleteTextView.java
+++ b/lib/java/com/google/android/material/textfield/MaterialAutoCompleteTextView.java
@@ -21,15 +21,21 @@
import static com.google.android.material.theme.overlay.MaterialThemeOverlay.wrap;
import android.content.Context;
+import android.content.res.ColorStateList;
import android.content.res.TypedArray;
+import android.graphics.Color;
import android.graphics.Rect;
+import android.graphics.drawable.ColorDrawable;
import android.graphics.drawable.Drawable;
+import android.graphics.drawable.RippleDrawable;
import android.os.Build.VERSION;
+import android.os.Build.VERSION_CODES;
import androidx.appcompat.widget.AppCompatAutoCompleteTextView;
import androidx.appcompat.widget.ListPopupWindow;
import android.text.InputType;
import android.util.AttributeSet;
import android.view.View;
+import android.view.ViewGroup;
import android.view.ViewGroup.LayoutParams;
import android.view.ViewParent;
import android.view.accessibility.AccessibilityManager;
@@ -38,12 +44,17 @@
import android.widget.ArrayAdapter;
import android.widget.Filterable;
import android.widget.ListAdapter;
+import android.widget.TextView;
import androidx.annotation.ArrayRes;
import androidx.annotation.LayoutRes;
import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
+import androidx.core.graphics.drawable.DrawableCompat;
+import androidx.core.view.ViewCompat;
+import com.google.android.material.color.MaterialColors;
import com.google.android.material.internal.ManufacturerUtils;
import com.google.android.material.internal.ThemeEnforcement;
+import com.google.android.material.resources.MaterialResources;
/**
* A special sub-class of {@link android.widget.AutoCompleteTextView} that is auto-inflated so that
@@ -51,10 +62,10 @@
* interacted through a screen reader.
*
*
The {@link ListPopupWindow} of the {@link android.widget.AutoCompleteTextView} is not modal,
- * so it does not grab accessibility focus. The {@link MaterialAutoCompleteTextView} changes that
- * by having a modal {@link ListPopupWindow} that is displayed instead of the non-modal one, so that
- * the first item of the popup is automatically focused. This simulates the behavior of the
- * {@link android.widget.Spinner}.
+ * so it does not grab accessibility focus. The {@link MaterialAutoCompleteTextView} changes that by
+ * having a modal {@link ListPopupWindow} that is displayed instead of the non-modal one, so that
+ * the first item of the popup is automatically focused. This simulates the behavior of the {@link
+ * android.widget.Spinner}.
*/
public class MaterialAutoCompleteTextView extends AppCompatAutoCompleteTextView {
@@ -65,6 +76,8 @@ public class MaterialAutoCompleteTextView extends AppCompatAutoCompleteTextView
@NonNull private final Rect tempRect = new Rect();
@LayoutRes private final int simpleItemLayout;
private final float popupElevation;
+ private int simpleItemSelectedColor;
+ @Nullable private ColorStateList simpleItemSelectedRippleColor;
public MaterialAutoCompleteTextView(@NonNull Context context) {
this(context, null);
@@ -100,15 +113,24 @@ public MaterialAutoCompleteTextView(
}
}
- simpleItemLayout = attributes.getResourceId(
- R.styleable.MaterialAutoCompleteTextView_simpleItemLayout,
- R.layout.mtrl_auto_complete_simple_item);
-
+ simpleItemLayout =
+ attributes.getResourceId(
+ R.styleable.MaterialAutoCompleteTextView_simpleItemLayout,
+ R.layout.mtrl_auto_complete_simple_item);
popupElevation =
attributes.getDimensionPixelOffset(
R.styleable.MaterialAutoCompleteTextView_android_popupElevation,
R.dimen.mtrl_exposed_dropdown_menu_popup_elevation);
+ simpleItemSelectedColor =
+ attributes.getColor(
+ R.styleable.MaterialAutoCompleteTextView_simpleItemSelectedColor, Color.TRANSPARENT);
+ simpleItemSelectedRippleColor =
+ MaterialResources.getColorStateList(
+ context,
+ attributes,
+ R.styleable.MaterialAutoCompleteTextView_simpleItemSelectedRippleColor);
+
accessibilityManager =
(AccessibilityManager) context.getSystemService(Context.ACCESSIBILITY_SERVICE);
@@ -191,7 +213,65 @@ public void setSimpleItems(@ArrayRes int stringArrayResId) {
* @see #setAdapter(ListAdapter)
*/
public void setSimpleItems(@NonNull String[] stringArray) {
- setAdapter(new ArrayAdapter<>(getContext(), simpleItemLayout, stringArray));
+ setAdapter(new MaterialArrayAdapter<>(getContext(), simpleItemLayout, stringArray));
+ }
+
+ /**
+ * Sets the color of the default selected popup dropdown item to be used along with
+ * {@code R.attr.simpleItemLayout}.
+ *
+ * @param simpleItemSelectedColor the selected item color
+ * @see #getSimpleItemSelectedColor()
+ * @see #setSimpleItems(int)
+ * @attr ref
+ * com.google.android.material.R.styleable#MaterialAutoCompleteTextView_simpleItemSelectedColor
+ */
+ public void setSimpleItemSelectedColor(int simpleItemSelectedColor) {
+ this.simpleItemSelectedColor = simpleItemSelectedColor;
+ if (getAdapter() instanceof MaterialArrayAdapter) {
+ ((MaterialArrayAdapter) getAdapter()).updateSelectedItemColorStateList();
+ }
+ }
+
+ /**
+ * Returns the color of the default selected popup dropdown item.
+ *
+ * @see #setSimpleItemSelectedColor(int)
+ * @attr ref
+ * com.google.android.material.R.styleable#MaterialAutoCompleteTextView_simpleItemSelectedColor
+ */
+ public int getSimpleItemSelectedColor() {
+ return simpleItemSelectedColor;
+ }
+
+ /**
+ * Sets the ripple color of the selected popup dropdown item to be used along with
+ * {@code R.attr.simpleItemLayout}.
+ *
+ * @param simpleItemSelectedRippleColor the ripple color state list
+ * @see #getSimpleItemSelectedRippleColor()
+ * @see #setSimpleItems(int)
+ * @attr ref
+ * com.google.android.material.R.styleable#MaterialAutoCompleteTextView_simpleItemSelectedRippleColor
+ */
+ public void setSimpleItemSelectedRippleColor(
+ @Nullable ColorStateList simpleItemSelectedRippleColor) {
+ this.simpleItemSelectedRippleColor = simpleItemSelectedRippleColor;
+ if (getAdapter() instanceof MaterialArrayAdapter) {
+ ((MaterialArrayAdapter) getAdapter()).updateSelectedItemColorStateList();
+ }
+ }
+
+ /**
+ * Returns the ripple color of the default selected popup dropdown item, or null if not set.
+ *
+ * @see #setSimpleItemSelectedRippleColor(ColorStateList)
+ * @attr ref
+ * com.google.android.material.R.styleable#MaterialAutoCompleteTextView_simpleItemSelectedRippleColor
+ */
+ @Nullable
+ public ColorStateList getSimpleItemSelectedRippleColor() {
+ return simpleItemSelectedRippleColor;
}
/**
@@ -325,4 +405,110 @@ private