Android: 在ListView上AutoCompleteTextView的顶部间距

4
AutoCompleteTextView会在弹出窗口中显示ListView以进行自动完成。附上详细问题的图片。在第一项之前,有一点白色边距。这个边距只在列表顶部可见。此问题在运行2.3的设备上可见,而在4.x上不可见。
请问有人能指出这种行为的原因并提供解决方法吗?
包含AutoCompleteTextview的布局的代码:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
          android:paddingLeft="8dp"
          android:paddingRight="8dp"
          android:layout_height="wrap_content"
          android:layout_width="match_parent">

<AutoCompleteTextView
        android:id="@+id/menu_search_field"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:background="@drawable/textfield_searchview_holo_light"
        android:clickable="true"
        android:hint="@string/search_hint"
        android:imeOptions="actionSearch"
        android:lines="1"
        android:singleLine="true"
        android:textColor="@color/header_text_color"
        android:textColorHint="@color/header_hint_text_color"
        android:textSize="14dip"/>

</LinearLayout>

列表视图中定义项目的布局。
<TextView xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="fill_parent"
    android:layout_height="wrap_content"
    android:padding="10dp"
    android:textSize="16sp"
    android:textColor="@android:color/white"
    android:background="@android:color/black"
    android:ellipsize="end"
    >
</TextView>

textfield_searchview_holo_light的可绘制对象

<?xml version="1.0" encoding="utf-8"?>
 <selector xmlns:android="http://schemas.android.com/apk/res/android">
    <item android:state_focused="true"  android:drawable="@drawable/textfield_search_default_holo_dark" />
    <item android:drawable="@drawable/textfield_search_default_holo_dark" />
</selector>

谢谢。

1
你能否上传这个视图的布局文件? - GrIsHu
可能是下拉菜单使用的样式有问题(因为您指出了问题是设备特定的)。但是您需要发布视图的布局代码。 - Supreethks
大家好... 有人知道任何解决方案吗? - SwapsAgNO3
1个回答

0
尝试向您的AutoCompleteTextView添加XML属性:
android:popupBackground="color_what_you_want_to_background"

在你的情况下,类似这样

android:popupBackground="@android:color/black"

希望能对你有所帮助。

非常感谢。但这不是一个解决方法吗?为什么一开始就存在边距?这是一个错误吗?不过你的解决方案确实解决了我的问题。 - SwapsAgNO3
@SwapsAgNO3 不知道这是否是一个错误.. 对于第一项来说,这种行为很奇怪.. 但很高兴,它解决了你的问题。 - vsvydenko

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