Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Customize divider / separator in dropdown of an AutocompleteTextview

I've seen this question asked some other times on the site, but no one couldn't get any answer.

Is there any way to customize the appearance of the divider in the dropdown showing when using an AutocompleteTextview in android?

It's pretty easy for a ListView, but using only an ArrayAdapter for the autocompletetextview, is there any way to customize the divider.

(Not the textview, I already know doing that)

like image 977
tchoum Avatar asked Aug 02 '12 12:08

tchoum


3 Answers

Im not sure how you can do it for single AutoCompleteTextView but I know how to set it for the whole application. This should also help you :)

<style name="MyTheme" parent="AppTheme">
        <item name="android:dropDownListViewStyle">@style/MyListViewStyle</item>
</style>

<style name="MyListViewStyle" parent="@android:style/Widget.ListView">
        <item name="android:divider">#F00</item>
        <item name="android:dividerHeight">1px</item>
</style>
like image 186
Mark Avatar answered Nov 06 '22 10:11

Mark


I didnt find any divider properties so I did this

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:orientation="vertical" android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:background="@color/black">

<TextView
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:textAppearance="?android:attr/textAppearanceMedium"
    android:text="Medium Text"
    android:id="@+id/textView129"
    android:textColor="#000000"
    android:background="@color/white"
    android:layout_marginBottom="1dp"
    android:paddingLeft="10dp"
    android:paddingRight="10dp"
    android:paddingTop="5dp"
    android:paddingBottom="5dp"/>
</LinearLayout>

So wat im doing is I have a background color for the Linear layout and another background color for the text View (textView's background color overlaps the linear layout's background color) now using the margin property and setting the bottom margin of textview to 1dp u'll get a clean line between elements....

like image 42
Subendra Sharma Avatar answered Nov 06 '22 10:11

Subendra Sharma


I had faced same problem and try many ways but not achieve result, at last i got a quick and easy way to set divider and divider lenght with AutocompleteTextview. Basically we can set a border from bottom side with TextView of ArrayAdapter Layout. Like as

step1. Make a layout for arrayadapetr like as

<?xml version="1.0" encoding="utf-8"?>
<TextView xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/testt"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:background="@drawable/background_single_line"
android:textColor="@drawable/text_color"
android:textAppearance="?android:attr/textAppearanceMediumInverse"
style="?android:attr/dropDownItemStyle"
android:maxLines="1"
android:padding="3dp"
android:textSize="16sp" />

step2: in drawable folder create new layout its name background_single_line.xml

<?xml version="1.0" encoding="utf-8"?>
<layer-list xmlns:android="http://schemas.android.com/apk/res/android">
<item>
    <shape android:shape="rectangle">
        <solid android:color="@android:color/black" />
    </shape>
</item>
<item android:bottom="1dp">
    <shape android:shape="rectangle">
        <solid android:color="@android:color/white" />
    </shape>
</item>

Finally looks as divider .

enter image description here

like image 44
Binesh Kumar Avatar answered Nov 06 '22 12:11

Binesh Kumar