删除下拉项的顶部和底部背景颜色

Remove the Top and Bottom background color of Dropdown Items

我有 TextInputLayout,我在其中使用文本自动完成功能并实现了性别下拉菜单。问题是下拉菜单背景中顶部和底部显示的白色 items.I 已将背景颜色设为黄色。

这是我的XML

<com.google.android.material.textfield.TextInputLayout
        android:id="@+id/textInputLayoutGender"
        style="@style/Widget.MaterialComponents.TextInputLayout.OutlinedBox.ExposedDropdownMenu"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_marginStart="32dp"
        android:layout_marginTop="70dp"
        android:layout_marginEnd="32dp"
        android:hint="Gender"
        android:textColorHint="#858585"
        app:boxCornerRadiusBottomEnd="45dp"
        app:boxCornerRadiusBottomStart="45dp"
        app:boxCornerRadiusTopEnd="45dp"
        app:boxCornerRadiusTopStart="45dp"
        app:boxStrokeColor="@color/edit_textbox_color"
        app:boxStrokeWidth="2dp"
        app:endIconTint="#FFC153"
        app:hintTextColor="@color/yellow"
        app:layout_constraintEnd_toEndOf="parent"
        app:layout_constraintHorizontal_bias="0.506"
        app:layout_constraintStart_toStartOf="parent"
        app:layout_constraintTop_toBottomOf="@+id/textViewInformation"
        tools:ignore="MissingConstraints">

        <AutoCompleteTextView
            android:id="@+id/gender"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:drawableStart="@drawable/sex"
            android:drawablePadding="16dp"
            android:fontFamily="@font/montserrat_medium"
            android:inputType="textNoSuggestions"
            android:textColor="@color/yellow" />

    </com.google.android.material.textfield.TextInputLayout>

这个我用于下拉项

<com.google.android.material.textview.MaterialTextView
    xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_height="wrap_content"
    android:layout_width="match_parent"
    android:id="@+id/textView"
    android:background="@color/yellow"
    android:textColor="@color/black"
    android:padding="14dp"
    >

</com.google.android.material.textview.MaterialTextView>

尝试像下面这样以编程方式应用背景可绘制对象:

autoCompleteTextView.setDropDownBackgroundDrawable(
    context.getResources().getDrawable(R.drawable.yellow_drawable));

创建 yellow_drawable.xml 纯黄色。

您可以使用

更改下拉菜单的背景图片
setDropDownBackgroundResource();

Here is the official document