Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

"android:dropDownAnchor" not working on Android Nougat (API 24)

I have created a simple AutoCompleteTextView like this :

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:orientation="vertical"
    android:layout_width="match_parent"
    android:layout_height="match_parent">
    <AutoCompleteTextView
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:id="@+id/query"
        android:dropDownAnchor="@id/dropdownDivider"
        android:dropDownWidth="match_parent"
        android:dropDownHeight="match_parent"
        android:inputType="text"
        android:android:imeOptions="actionSearch"/>
    <View
        android:layout_width="match_parent"
        android:layout_height="2dp"
        android:background="#ccc"
        android:id="@+id/dropdownDivider"/>
</LinearLayout>

The dropdown is supposed to come below the autocompletetextview and the view called "dropdownDivider". It is not supposed to overlap the autocompletetextview. This was achieved by using the android:dropDownAnchor property. This works perfectly in API versions less than 23.

However in API 24 (Android Nougat), the dropdown overlaps the autocompletetextview and occupies full screen.

What I tried:

  • Replaced <AutoCompleteTextView/> with <android.support.v7.widget.AppCompatAutoCompleteTextView/> but that didn't help.
  • Tried this, this, this and a few more answers but nothing solved the issue.

Any ideas?

like image 447
kds23 Avatar asked Oct 10 '16 12:10

kds23


1 Answers

Setting the drop down height programmatically to wrap content fix the issue for me. autoCompleteTextView.setDropDownHeight(ViewGroup.LayoutParams.WRAP_CONTENT);

like image 187
Yossi Segev Avatar answered Nov 13 '22 05:11

Yossi Segev