1

Here is my AutoCompleteTextView

<AutoCompleteTextView
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:dividerHeight="4dp"
        android:gravity="center"
        android:inputType="textCapWords|textAutoCorrect"
        android:textColor="@color/font_autocomplete"
        android:textSize="18sp" />

Does anyone know why setting the android:dividerHeight has no effect?

learner
  • 11,490
  • 26
  • 97
  • 169

2 Answers2

5

An AutoCompleteTextView is a compound View - it's got both an EditText component and a floating DropDown component. The EditText component is straightforward to style, but the DropDown is difficult because it's a mixture of attributes on the AutoCompleteTextView itself and styles set in the theme via android:dropDownListViewStyle.

If you want to change the dividers, you have to create a theme and point that to a style, which isn't an immediately obvious solution:

<style name="MyTheme">
  <item name="android:dropDownListViewStyle">@style/DropDownListViewStyle</item>
</style>

<style name="DropDownListViewStyle">
  <item name="android:dividerHeight">4dp</item>
</style>

Note, however, that these style changes will apply across your whole Application. So if you've got other DropDown components in your UI, they'll likely be affected as well.

bstar55
  • 3,542
  • 3
  • 20
  • 24
0

Autocompletetextview drop down custom item divider can be implemented using below item layout and drawable. For complete reference http://www.zoftino.com/android-autocompletetextview-custom-layout-and-adapter

Custom layout

 <?xml version="1.0" encoding="utf-8"?>
<android.support.constraint.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    android:layout_width="match_parent"
    android:layout_height="match_parent">

    <TextView xmlns:android="http://schemas.android.com/apk/res/android"
        android:id="@+id/textView"
        style="?android:attr/dropDownItemStyle"
        android:layout_width="match_parent"
        android:layout_height="?android:attr/listPreferredItemHeight"
        android:ellipsize="marquee"
        android:singleLine="true"
        android:textAppearance="?android:attr/textAppearanceLargePopupMenu"
        app:layout_constraintEnd_toEndOf="parent"
        app:layout_constraintStart_toStartOf="parent"
        app:layout_constraintTop_toTopOf="parent" />

    <Button
        android:id="@+id/button"
        android:layout_width="match_parent"
        android:layout_height="6dp"
        android:enabled="false"
        android:background="@drawable/divider"
        app:layout_constraintEnd_toEndOf="parent"
        app:layout_constraintStart_toStartOf="parent"
        app:layout_constraintTop_toBottomOf="@+id/textView" />

</android.support.constraint.ConstraintLayout> 

Custom drawable

 <?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android"
    android:tint="#42a5f5"
    android:shape="rectangle">
    <corners
        android:radius="4dp"/>
    <size
        android:height="6dp" />
    <solid android:color="#42a5f5" />
</shape> 
Arnav Rao
  • 6,692
  • 2
  • 34
  • 31