简体   繁体   中英

Android: AutoCompleteTextView top margin on ListView

The AutoCompleteTextView displays a ListView in a popup for auto completion. Attached is the image detailing the problem. Just before the first item, there is little white margin. This margin is only visible on the top of the list. This problem is seen on device running 2.3, while on 4.x this problem is not visible.

在此输入图像描述

Can somebody point out the reason for this behavior and a way to fix it.

The code for Layout containing 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>

The layout defining the item in the Listview.

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

And the drawable for 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>

Thanks.

Try to add XML attribute to your AutoCompleteTextView:

android:popupBackground="color_what_you_want_to_background"

in your case something like

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

Hope, it helps you

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM