Westside Tony Westside Tony - 1 year ago 118
Android Question

Autocompletetextview dropdown behind soft keyboard in dialog fragment

I have a dialog fragment in my app with an

autocompletetextview
in it, but the drop-down list instead of align with the soft keyboard's top, is placed behind, not giving access to some of the items.

Here is the layout:

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:gravity="center"
android:padding="10dp"
android:orientation="horizontal"
android:windowSoftInputMode="adjustPan|adjustResize">

<android.widget.AutoCompleteTextView
android:layout_width="0dp"
android:layout_height="wrap_content"
android:id="@+id/customDialogAtocompleteTextview"
android:layout_weight=".7"
android:layout_gravity="top" />

<LinearLayout
android:orientation="vertical"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight=".3">
<Button
android:id="@+id/customDialogBtOk"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="Aceptar"/>
<Button
android:id="@+id/customDialogBtSearch"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="Buscar"/>
<Button
android:id="@+id/customDialogBtMore"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="Mas"/>
</LinearLayout>

</LinearLayout>


So how can I make it to align with the keyboard?

Answer Source

Theory says that android:windowSoftInputMode="adjustPan|adjustResize"shoul do this but for some reason it don't, so you have to do the same programatically:

getDialog().getWindow().setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_ADJUST_RESIZE);

Aaaaaand the magic happens

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download