Android 自动完成下拉列表的连锁反应

Android 自动完成下拉列表的连锁反应,android,autocompletetextview,Android,Autocompletetextview,我有一个自动完成的文本视图,其中的项目布局如下(文本视图) 当下拉列表显示时,背景为灰色,当我点击并按住某个项目时,会显示涟漪效应。 将ripple effect设置为默认值非常好,但是如何在保持ripple effect的同时将背景设置为白色?您需要定义您的ripple drawable-v21/list\u item\u ripple.xml <?xml version="1.0" encoding="utf-8"?> <ripple xmlns:android="ht

我有一个自动完成的文本视图,其中的项目布局如下(文本视图)


当下拉列表显示时,背景为灰色,当我点击并按住某个项目时,会显示涟漪效应。
将ripple effect设置为默认值非常好,但是如何在保持ripple effect的同时将背景设置为白色?

您需要定义您的ripple

drawable-v21/list\u item\u 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>
<shape xmlns:android="http://schemas.android.com/apk/res/android">
  <solid android:color="@android:color/white" />
</shape>
然后将其设置为
线性布局的背景:

android:background="@drawable/list_item_ripple"

显然,您可以将颜色更改为最适合您的颜色

您需要定义纹波

drawable-v21/list\u item\u 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>
<shape xmlns:android="http://schemas.android.com/apk/res/android">
  <solid android:color="@android:color/white" />
</shape>
然后将其设置为
线性布局的背景:

android:background="@drawable/list_item_ripple"

显然,您可以将颜色更改为最适合您的颜色

设置AutocompleteTextview的PopubBackground属性,如下所示解决了我的问题

<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"/>


触摸下拉列表中的项目会触发ripple动画,尽管我还没有定义任何动画。似乎ripple动画是默认内置的。我正在使用API Level 21设备进行测试。

如下所示设置AutocompleteTextview的PopubBackground属性可以解决我的问题

<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"/>


触摸下拉列表中的项目会触发ripple动画,尽管我还没有定义任何动画。似乎ripple动画是默认内置的。我正在使用API Level 21设备进行测试。

为了使用ripple xml标记,我将被迫将我的min sdk版本设置为21。如果可能的话,我希望避免这种情况。这就是为什么我说把它放在
drawable-v21
文件夹中。您可以在
drawable
文件夹中定义相同的布局,并按常规
drawable/state\u
behavior以使用ripple xml标记,我将被迫将我的min sdk版本设置为21。如果可能的话,我希望避免这种情况。这就是为什么我说把它放在
drawable-v21
文件夹中。您可以在
drawable
文件夹中定义相同的布局,并按常规的
drawable/state\u
行为