Search code examples
androidautocompletetextview

Adding padding on android AutoCompleteTextView popup


For the last two hour and a half i had been trying to do something really simple: change the padding in the Android's AutoCompleteTextView's popup (the one that shows the auto complete options).
i'm trying to do this because the item in my app has the height of the text (i'm not sure why), so i want to make it easier to click on. But every think i could find didn't work at all.
So i really would be glad if anyone could spot a light in this problem or give an alternative solution.

And just for the record, i'm using android studio, and i had removed the support API (since my min API is 16), so my app is using 100% native resorts only.


Solution

  • I just found a way to make it, i had to make a custom view layout with an textview already including the item's padding. Than i created a custom adapter with uses this layout.

    The layout goes like this

    <?xml version="1.0" encoding="utf-8"?>
    <TextView xmlns:android="http://schemas.android.com/apk/res/android"
        android:singleLine="true"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:ellipsize="marquee"
        android:layout_margin="0dp"
        android:paddingLeft="@dimen/thin_margin"
        android:paddingRight="@dimen/thin_margin"
        android:paddingTop="@dimen/list_1line_item_padding"
        android:paddingBottom="@dimen/list_1line_item_padding"/>
    

    And in the custom adapter just used it in the getView method

    itemView = LayoutInflater.from(ctx).inflate(R.layout.list_1line_item, null);