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

时间:2021-06-22 06:21:55

标签: android xml android-layout

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

这是我的 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>

2 个答案:

答案 0 :(得分:2)

尝试以编程方式应用背景可绘制,如下所示:

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

用纯黄色创建 yellow_drawable.xml

答案 1 :(得分:2)

您可以使用

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

Here is the official document