Autocompletetextview dropdown behind soft keyboard in dialog fragment
Asked Answered
L

2

13

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?

Lamentable answered 11/10, 2016 at 10:26 Comment(0)
L
29

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

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

Aand the magic happens!!!

Lamentable answered 11/10, 2016 at 16:9 Comment(2)
Can you please elaborate the answer , its way too conise to use this , i dont know how to get dialog of autocomplete text viewEma
This suggestion doesn't work. The TextView is no longer obscured, but the dropdown is blocked also.Headdress
I
5

[update] in my case.. cause i use bottomShetDialogFragment with autocomplete inside. drop down not show cause i not set dropdownanchor for autocomplete. just add android:dropDownAnchor="@id/layout_above_this_autocomplete" and work perfect

ad news style in your style.xml

<style name="AppBottomSheetDialogTheme" parent="Theme.Design.Light.BottomSheetDialog">
    <item name="bottomSheetStyle">@style/AppModalStyle</item>
    <item name="android:windowIsFloating">false</item>
    <item name="android:windowSoftInputMode">adjustResize</item>
</style>
<style name="AppModalStyle" parent="Widget.Design.BottomSheet.Modal">
<item name="behavior_peekHeight">400dp</item>

</style>

in your bottomshetdialog framgnet. oncreate -> setStyle(DialogFragment.STYLE_NORMAL, R.style.AppBottomSheetDialogTheme)

override fun getTheme(): Int {
    return R.style.AppBottomSheetDialogTheme
}

result

Interlocutrix answered 23/10, 2019 at 4:10 Comment(1)
Thank you sir! Spent an hour trying a dozen things and this was the solution.Festinate

© 2022 - 2024 — McMap. All rights reserved.