18

I have an Autocompletetextview dropping down the suggestions list, up to the border of the soft-keyboard.

Then, when scrolling over the suggestions list: - (in a gingerbread phone) the drop-down-menu automatically increases height covering the keyboard, which is nice since it shows more items. - (in an ICS emulator) the drop-down-menu does not increase height over the keyboard.

Is this related to some system property? Is there a way to force the first behavior also in ICS?

rmarau
  • 388
  • 1
  • 4
  • 12

7 Answers7

28

Just add android:dropDownHeight="100dp" to the AutoCompleteTextView tag in your layout file, it will work.

CopsOnRoad
  • 237,138
  • 77
  • 654
  • 440
Deepak Goel
  • 5,624
  • 6
  • 39
  • 53
  • 2
    I would give you +million if I could... You made my day! – keybee Mar 27 '13 at 08:37
  • 3
    This is a workaround, given that different devices have different aspect ratios, the 100dp is not a magical number, you need to tweak it to different devices and OS versios. However, this is the only way of solving it that I've found so far, so I'm upvoting this answer. Thanks! – shalafi Jan 28 '14 at 17:13
  • Days of searching... Days of agony.. with such a simple fix. Thank you – Brandon Feb 18 '15 at 21:25
  • The most direct and stupid solution – Vitaly Jan 24 '22 at 17:07
2

Let me explain my little trick to avoid that the "drop-down" displays behind the keyboard. The trick is with the dropDownAnchor property. The solution is set the anchor with a view located on the top of the screen, so the menu will leave from that position, and therefore, will not be covered by the keyboard. For example:

android:dropDownAnchor="@+id/topview"

I know that is an ugly solution but this control is too limited.

Laurent
  • 14,122
  • 13
  • 57
  • 89
pgarriga
  • 610
  • 3
  • 8
  • 22
1

You can also use android:dropDownAnchor="@id/ to anchor the dropdown to a view.

Yotam Omer
  • 15,310
  • 11
  • 62
  • 65
Hoang
  • 11
  • 1
1

Just add getActivity().getWindow().setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_ADJUST_RESIZE); to your fragment or activity

EzeKieL
  • 11
  • 4
1

A simple solution that works perfectly with all resolutions is to use the android:dropDownAnchor property with a resource ID that references your activity toolbar.

<my.app.ContactAutoCompleteTextView
                            android:id="@+id/autocomplete_textview"
                            android:layout_width="match_parent"
                            android:layout_height="wrap_content"
                            android:gravity="top"
                            android:dropDownAnchor="@id/appbar"
                            android:inputType="text|textMultiLine|textCapSentences|textAutoCorrect"
                            android:paddingBottom="12dp"
                            android:textColor="@color/text_primary"
                            android:textColorLink="@color/secondary"
                            android:textSize="@dimen/text_medium" />
Laurent
  • 14,122
  • 13
  • 57
  • 89
0

You need to do two things. First, adjust the soft input mode of that activity in the manifest.

android:windowSoftInputMode="stateHidden|adjustResize"

This ensures views are laid out again when the keyboard is shown. Then, set a global layout listener in your oncreate on the top level view to do the dropdown height calculation when the layout changes. Adjust the dropdown height to be the height of everything below the keyboard, minus some padding if you want.

v.getViewTreeObserver().addOnGlobalLayoutListener(new OnGlobalLayoutListener() {

        @Override
        public void onGlobalLayout() {
                autoCompleteView.setDropDownHeight(view2.getHeight());
}

Where view2 is the view/layout that includes everything below the autocompleteview.

sbaar
  • 1,429
  • 1
  • 17
  • 33
0

If none of the above solutions worked. try this

android:dropDownHeight="match_parent"

or

android:dropDownHeight="500dp"

If we didn't mention the dropdown height, it would be considered wrap_content. Therefore the item will show behind the soft keyboard.