Волновой эффект в выпадающем списке автозаполнения

У меня есть автозаполнение textview со следующим макетом для элементов (Textview)

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
          android:layout_width="match_parent"
          android:layout_height="wrap_content"
          android:layout_marginLeft="@dimen/activity_horizontal_margin"
          android:gravity="center_vertical"
          android:orientation="vertical">

<TextView
    android:id="@+id/suggestion"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:layout_weight="1"
    android:gravity="center_vertical"
    android:minHeight="?android:attr/listPreferredItemHeightSmall"
    android:paddingEnd="?android:attr/listPreferredItemPaddingEnd"
    android:paddingLeft="?android:attr/listPreferredItemPaddingLeft"
    android:paddingRight="?android:attr/listPreferredItemPaddingRight"
    android:paddingStart="?android:attr/listPreferredItemPaddingStart"
    android:textAppearance="?android:attr/textAppearanceListItemSmall"
    android:textColor="@color/black"/>

<View
    android:layout_width="match_parent"
    android:layout_height="1dp"
    android:background="?android:attr/listDivider"/>
</LinearLayout>

Когда отображается раскрывающийся список, фон становится серым, а когда я нажимаю и удерживаю элемент, появляется эффект ряби. Иметь эффект ряби по умолчанию - это здорово, но как я могу установить белый фон, сохраняя эффект ряби?

2 ответа

Ты захочешь определить свою рябь

drawable-v21/list_item_ripple.xml

<?xml version="1.0" encoding="utf-8"?>
<ripple xmlns:android="http://schemas.android.com/apk/res/android"
    android:color="@android:color/blue">
    <item android:drawable="@layout/regular_list_background"/>
</ripple>

layout/regular_list_background.xml

<shape xmlns:android="http://schemas.android.com/apk/res/android">
  <solid android:color="@android:color/white" />
</shape>

А затем установите это в качестве фона вашего LinearLayout:

android:background="@drawable/list_item_ripple"

Очевидно, вы можете изменить цвет на любой, который подходит вам лучше всего

Установка атрибута popupBackground для AutocompleteTextview, как показано ниже, решает мою проблему.

<android.support.v7.widget.AppCompatAutoCompleteTextView
            android:id="@+id/autocomplete"
            android:layout_width="0dp"
            android:layout_height="@dimen/edit_box_height"
            android:layout_weight="1"
            android:background="@android:color/transparent"
            android:completionThreshold="1"
            android:dropDownAnchor="@id/box"
            android:hint="@string/name_hint"
            android:imeOptions="actionNext"
            android:inputType="textCapSentences"
            android:popupBackground="@color/white"
            android:singleLine="true"
            android:textAppearance="?android:attr/textAppearanceListItemSmall"
            android:textColor="@android:color/black"/>

Прикосновение к элементам раскрывающегося списка вызывает анимацию пульсации, хотя я ее не определил. Похоже, что анимация пульсации встроена по умолчанию. Я тестирую с устройством уровня API 21.

Другие вопросы по тегам