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
.
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.
The issue appears to be happening because of android:popupBackground="@null"
Remove --> android:popupBackground="@null"
from AutoCompleteTextView
and than check it.
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With