Home > database >  AutoCompleteText not update popup background
AutoCompleteText not update popup background

Time:02-04

I am using AppCompatAutoCompleteTextView but I cannot change the background of the dropdown list or neither the color of the background of the selector. I tried color or drawable but nothing change.

     <androidx.appcompat.widget.AppCompatAutoCompleteTextView
                    android:id="@ id/topicEt"
                    android:layout_width="match_parent"
                    android:layout_height="48dp"
                    android:layout_marginTop="4dp"
                    android:background="@drawable/corner_shape_spinner_darkness"
                    android:dropDownHeight="wrap_content"
                    android:hint="@string/support_select_topic"
                    android:inputType="none"
                    android:editable="false"
                    android:paddingStart="12dp"
                    android:textAppearance="@style/Body_12"
                    android:textColor="@color/white"
                    android:textColorHint="@color/gray200"
                    android:drawableEnd="@drawable/dropdown_icon_selector"
                    android:paddingEnd="14dp"
                    android:dropDownSelector="@color/lightness100"
                    android:popupBackground="@color/darkness100"/>

Any idea ?

CodePudding user response:

The background color of the dropdown list in the AppCompatAutoCompleteTextView can be changed by setting the popupBackground attribute. However, if you're unable to change the background color, try the following:

Step 1: Create a custom drawable for the popup background and set it using the popupBackground attribute.

<androidx.appcompat.widget.AppCompatAutoCompleteTextView
                ...
                android:popupBackground="@drawable/custom_popup_background"
                ... />

Step 2: Create a custom dropdown selector and set it using the dropDownSelector attribute.

<androidx.appcompat.widget.AppCompatAutoCompleteTextView
                ...
                android:dropDownSelector="@drawable/custom_dropdown_selector"
                ... />

Try these steps and let me know if it helps.

CodePudding user response:

You can change the AppCompatAutoCompleteTextView selector background with app:backgroundTint attribute.

And change the background of the dropdown list programmatically with either:

autoCompleteTV.setDropDownBackgroundDrawable(ColorDrawable(Color.RED))
autoCompleteTV.setDropDownBackgroundResource(resourceId) // takes a color/drawable resource
  • Related