MaterialAutoCompleteTextView

public class MaterialAutoCompleteTextView
extends AppCompatAutoCompleteTextView

java.lang.Object
   ↳ android.view.View
     ↳ android.widget.TextView
       ↳ android.widget.EditText
         ↳ android.widget.AutoCompleteTextView
           ↳ androidx.appcompat.widget.AppCompatAutoCompleteTextView
             ↳ com.google.android.material.textfield.MaterialAutoCompleteTextView


A special sub-class of AutoCompleteTextView that is auto-inflated so that auto-complete text fields (e.g., for an Exposed Dropdown Menu) are accessible when being interacted through a screen reader.

The ListPopupWindow of the AutoCompleteTextView is not modal, so it does not grab accessibility focus. The MaterialAutoCompleteTextView changes that by having a modal ListPopupWindow that is displayed instead of the non-modal one, so that the first item of the popup is automatically focused. This simulates the behavior of the Spinner.

Summary

XML attributes

MaterialAutoCompleteTextView_android_popupElevation  
MaterialAutoCompleteTextView_simpleItemSelectedColor  
MaterialAutoCompleteTextView_simpleItemSelectedRippleColor  

Inherited constants

Inherited fields

Public constructors

MaterialAutoCompleteTextView(Context context)
MaterialAutoCompleteTextView(Context context, AttributeSet attributeSet)
MaterialAutoCompleteTextView(Context context, AttributeSet attributeSet, int defStyleAttr)

Public methods

CharSequence getHint()
float getPopupElevation()

Returns the elevation of the dropdown popup.

int getSimpleItemSelectedColor()

Returns the color of the default selected popup dropdown item.

ColorStateList getSimpleItemSelectedRippleColor()

Returns the ripple color of the default selected popup dropdown item, or null if not set.

<T extends ListAdapter & Filterable> void setAdapter(T adapter)
void setOnItemSelectedListener(AdapterView.OnItemSelectedListener listener)
void setRawInputType(int type)
void setSimpleItemSelectedColor(int simpleItemSelectedColor)

Sets the color of the default selected popup dropdown item to be used along with R.attr.simpleItemLayout.

void setSimpleItemSelectedRippleColor(ColorStateList simpleItemSelectedRippleColor)

Sets the ripple color of the selected popup dropdown item to be used along with R.attr.simpleItemLayout.

void setSimpleItems(int stringArrayResId)

Sets the simple string items of auto-completion with the given string array resource.

void setSimpleItems(String[] stringArray)

Sets the simple string items of auto-completion with the given string array.

void showDropDown()

Protected methods

void onAttachedToWindow()
void onMeasure(int widthMeasureSpec, int heightMeasureSpec)

Inherited methods

XML attributes

MaterialAutoCompleteTextView_android_popupElevation

Related methods:

MaterialAutoCompleteTextView_simpleItemSelectedColor

Related methods:

MaterialAutoCompleteTextView_simpleItemSelectedRippleColor

Related methods:

Public constructors

MaterialAutoCompleteTextView

public MaterialAutoCompleteTextView (Context context)

Parameters
context Context

MaterialAutoCompleteTextView

public MaterialAutoCompleteTextView (Context context, 
                AttributeSet attributeSet)

Parameters
context Context

attributeSet AttributeSet

MaterialAutoCompleteTextView

public MaterialAutoCompleteTextView (Context context, 
                AttributeSet attributeSet, 
                int defStyleAttr)

Parameters
context Context

attributeSet AttributeSet

defStyleAttr int

Public methods

getHint

public CharSequence getHint ()

Returns
CharSequence

getPopupElevation

public float getPopupElevation ()

Returns the elevation of the dropdown popup.

Related XML Attributes:

Returns
float

getSimpleItemSelectedColor

public int getSimpleItemSelectedColor ()

Returns the color of the default selected popup dropdown item.

Related XML Attributes:

Returns
int

getSimpleItemSelectedRippleColor

public ColorStateList getSimpleItemSelectedRippleColor ()

Returns the ripple color of the default selected popup dropdown item, or null if not set.

Related XML Attributes:

Returns
ColorStateList

setAdapter

public void setAdapter (T adapter)

Parameters
adapter T

setOnItemSelectedListener

public void setOnItemSelectedListener (AdapterView.OnItemSelectedListener listener)

Parameters
listener AdapterView.OnItemSelectedListener

setRawInputType

public void setRawInputType (int type)

Parameters
type int

setSimpleItemSelectedColor

public void setSimpleItemSelectedColor (int simpleItemSelectedColor)

Sets the color of the default selected popup dropdown item to be used along with R.attr.simpleItemLayout.

Related XML Attributes:

Parameters
simpleItemSelectedColor int: the selected item color

setSimpleItemSelectedRippleColor

public void setSimpleItemSelectedRippleColor (ColorStateList simpleItemSelectedRippleColor)

Sets the ripple color of the selected popup dropdown item to be used along with R.attr.simpleItemLayout.

Related XML Attributes:

Parameters
simpleItemSelectedRippleColor ColorStateList: the ripple color state list

setSimpleItems

public void setSimpleItems (int stringArrayResId)

Sets the simple string items of auto-completion with the given string array resource. This method will create a default ArrayAdapter with a default item layout specified by R.attr.simpleItemLayout to display auto-complete items.

Parameters
stringArrayResId int

setSimpleItems

public void setSimpleItems (String[] stringArray)

Sets the simple string items of auto-completion with the given string array. This method will create a default ArrayAdapter with a default item layout specified by R.attr.simpleItemLayout to display auto-complete items.

Parameters
stringArray String

showDropDown

public void showDropDown ()

Protected methods

onAttachedToWindow

protected void onAttachedToWindow ()

onMeasure

protected void onMeasure (int widthMeasureSpec, 
                int heightMeasureSpec)

Parameters
widthMeasureSpec int

heightMeasureSpec int