从AutoCompleteTextView下拉菜单中移除阴影

11

我正在尝试创建一个全宽度自动完成文本框

到目前为止,我认为文本框本身看起来不错。问题出在自动完成弹出窗口上。它有一个非常粗犷的阴影,我就是无法摆脱它。
别误会,我仍然想要这个阴影,但只要一个微妙的阴影,仅出现在弹出窗口底部,而不是全部(特别是顶部,那真的很奇怪)。

像这样:

这就是我想要的

这是我的效果(对于巨大的图像感到抱歉):

我到目前为止拥有的

代码

activity_main.xml:

<AutoCompleteTextView
    android:id="@+id/actvSearch"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:layout_alignParentTop="true"
    android:layout_marginBottom="8dp"
    android:background="@drawable/full_width_input"
    android:completionThreshold="1"
    android:hint="Search a movie..."
    android:textColorHint="#BDBDBD"
    android:elevation="0dp"
    android:popupBackground="@android:color/white" />

full_width_input.xml:

<selector xmlns:android="http://schemas.android.com/apk/res/android">
    <item android:top="-1dp" android:right="-1dp" android:left="-1dp">
        <shape android:shape="rectangle">
            <padding android:bottom="20dp" android:top="20dp" android:left="16dp" android:right="16dp" />
            <solid android:color="@android:color/white" />
            <stroke android:width="1dp" android:color="#E0E0E0" />
        </shape>
    </item>
</selector>
4个回答

12

使用 android:popupElevation="0" 属性。

<AutoCompleteTextView
    android:id="@+id/actvSearch"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:layout_alignParentTop="true"
    android:layout_marginBottom="8dp"
    android:background="@drawable/full_width_input"
    android:completionThreshold="1"
    android:hint="Search a movie..."
    android:textColorHint="#BDBDBD"
    android:popupElevation="0dp"
    android:popupBackground="@android:color/white" />

6
这个问题有点旧了,但是无论如何。我刚刚遇到了这个问题。我正在为我的自动完成使用android:popupBackground="@null",但在Android 6上它不能正常工作(我刚测试过)。
取而代之的是使用android:popupBackground="@android:color/transparent"(它也适用于Android 4.4和5.0)。

5
如果我们在AutoCompleteTextView中设置android:popupBackground="@null",并将适配器行的背景设置为白色,就可以实现这一目标。希望对您有所帮助。

谢谢你的答复!我尝试了你的解决方案,效果差不多了。现在没有阴影了,但是似乎每一行的白色背景并没有影响到项目的实际背景。现在,就像这个列表有一个透明的背景一样。 - Gofilord

-5
我最终所做的是使用 ListView 手动创建自动完成功能。
经过一些尝试,现在我拥有了完全符合我的设计思路的效果。

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接