简体   繁体   English

Android:ListView上的AutoCompleteTextView上边距

[英]Android: AutoCompleteTextView top margin on ListView

The AutoCompleteTextView displays a ListView in a popup for auto completion. AutoCompleteTextView在弹出窗口中显示ListView以自动完成。 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. 在运行2.3的设备上可以看到此问题,而在4.x上,此问题不可见。

在此输入图像描述

Can somebody point out the reason for this behavior and a way to fix it. 有人可以指出这种行为的原因和解决方法。

The code for Layout containing AutoCompleteTextview 包含AutoCompleteTextview的Layout代码

<?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. 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 和textfield_searchview_holo_light的drawable

<?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: 尝试将XML属性添加到AutoCompleteTextView:

android:popupBackground="color_what_you_want_to_background"

in your case something like 在你的情况下像

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

Hope, it helps you 希望,它可以帮助你

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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