Android AutoCompleteTextView建议与TextView重叠

时间:2013-10-21 15:38:06

标签: android autocompletetextview

我正在使用Google地图制作应用程序。我正在使用AutoCompleteTextView来获取地点的建议。输出如下:

enter image description here

从图像中可以看出,建议框的边框与TextView重叠。我在线性布局中使用带有Textview的自定义项布局。

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:background="#fff"
    android:orientation="horizontal" >

    <TextView
        android:id="@+id/resultValue"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:background="#fff"
        android:paddingBottom="5dp"
        android:paddingLeft="5dp"
        android:paddingRight="5dp"
        android:paddingTop="5dp"
        android:textColor="#474040"
        android:textSize="15sp" />

</LinearLayout>

有没有办法将建议窗口关闭,并删除或更改建议窗口的灰色边框的颜色?

3 个答案:

答案 0 :(得分:3)

与接受的答案做同样的事情,但仍然存在重叠问题。要解决此问题:

autocompleteView.setDropDownVerticalOffset(0);

答案 1 :(得分:2)

尝试这样, android:popupBackground =“#EFEEEC” //根据您想要的建议框边框进行更改

<AutoCompleteTextView
            android:id="@+id/autocomplete"
            android:layout_width="fill_parent"
            android:layout_height="wrap_content"
            android:layout_margin="10dp"
            android:background="@drawable/text_area"
            android:inputType="text|textNoSuggestions|textMultiLine"
            android:paddingLeft="10dp"
            android:popupBackground="#EFEEEC"
            android:textColor="#333333"
            android:textColorHint="#9c9c9c"
            android:textSize="18sp"
            android:completionThreshold="1" />

和auto_textview.xml

<TextView xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="fill_parent"
    android:layout_height="wrap_content"
    android:padding="12dp"
    android:textColor="#333333"
    android:layout_margin="15dp"
    android:textSize="16sp" >
</TextView>

text_area9.png

enter image description here

最终输出看起来像

enter image description here

希望这对你有所帮助。

答案 2 :(得分:0)

使用像

这样的自定义绘图
AutoCompleteTextView txtNames= (AutoCompleteTextView)findViewById(R.id.editBox);
ArrayAdapter<String> adapter = new ArrayAdapter<String>(this, R.drawable.customlist, restList);
txtRestNames.setAdapter(adapter);

并将自定义列表添加为

    <?xml version="1.0" encoding="utf-8"?>
  <TextView xmlns:android="http://schemas.android.com/apk/res/android" 
    android:id="@+id/cust_view"  
    android:layout_width="match_parent" 
    android:layout_height="wrap_content"
    android:padding="5dip"
    android:textSize="12dp" 
    android:singleLine="false"/>

更改参数/颜色以满足您的需要。试试吧......希望有所帮助