Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I stop my AutoCompleteTextView dropdown from scrolling over my AutoCompleteTextView?

I have a AppCompatAutoCompleteTextView with an anchor which is further down than the AppCompatAutoCompleteTextView. This is by design and can not be changed. When I scroll on the dropdown, the dropdown moves up and on top of the AppCompatAutoCompleteTextView.

enter image description here

Is that the way it should work?

This is my code:

Main activity xml:

<RelativeLayout
    xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:paddingBottom="@dimen/activity_vertical_margin"
    android:paddingLeft="@dimen/activity_horizontal_margin"
    android:paddingRight="@dimen/activity_horizontal_margin"
    android:paddingTop="@dimen/activity_vertical_margin"
    tools:context="com.autocompletetest.MainActivity">
    <android.support.v7.widget.AppCompatAutoCompleteTextView
        android:id="@+id/autocomplete"
        android:layout_width="match_parent"
        android:layout_height="32dp"

        android:layout_gravity="center"
        android:layout_marginLeft="8dp"
        android:layout_weight="1"
        android:alpha="0.87"
        android:background="#ffffff"
        android:dropDownWidth="match_parent"
        android:dropDownAnchor="@+id/anchor"
        android:gravity="center_vertical"

        android:hint="entervalue"
        android:inputType="textUri"
        android:popupBackground="@null"
        android:selectAllOnFocus="true"
        android:singleLine="true"
        android:textColor="#000000"
        android:textSize="14sp"
        android:layout_alignParentTop="true"
        android:textColorHint="#000000"
        />
    <View
        android:layout_width="match_parent"
        android:layout_height="5dp"
        android:layout_marginTop="3dp"
        android:layout_below="@+id/autocomplete"
        android:id="@+id/anchor"
        android:background="#aaaaaa"/>
</RelativeLayout>

Main activity java:

AppCompatAutoCompleteTextView auto = (AppCompatAutoCompleteTextView) findViewById(R.id.autocomplete);
        String[] countries = getResources().getStringArray(R.array.colors);
        ArrayAdapter<String> adapter = new ArrayAdapter<String>(this,android.R.layout.simple_list_item_1,countries);
        auto.setAdapter(adapter);

EDIT: I should mention I saw this behavior on Marshmallow.

like image 666
casolorz Avatar asked May 05 '16 15:05

casolorz


3 Answers

The issue appears to be happening because of android:popupBackground="@null"

like image 129
casolorz Avatar answered Nov 15 '22 03:11

casolorz


Remove --> android:popupBackground="@null"
from AutoCompleteTextView

and than check it.

like image 33
Mr. Mad Avatar answered Nov 15 '22 03:11

Mr. Mad


Per documentation it says that:

View to anchor the auto-complete dropdown to. If not specified, the text view itself is used.

Do you need your custom anchor at all? I imagine the default doesn't have this behavior likely caused by your relative layout.

like image 38
egfconnor Avatar answered Nov 15 '22 03:11

egfconnor