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_dropDownBackgroundTint  
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

void dismissDropDown()
ColorStateList getDropDownBackgroundTintList()

Returns the color of the popup dropdown container.

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.

void onWindowFocusChanged(boolean hasWindowFocus)
<T extends ListAdapter & Filterable> void setAdapter(T adapter)
void setDropDownBackgroundDrawable(Drawable d)
void setDropDownBackgroundTint(int dropDownBackgroundColor)

Sets the color of the popup dropdown container.

void setDropDownBackgroundTintList(ColorStateList dropDownBackgroundTint)

Sets the color of the popup dropdown container.

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 onDetachedFromWindow()
void onMeasure(int widthMeasureSpec, int heightMeasureSpec)

Inherited methods

XML attributes

MaterialAutoCompleteTextView_android_popupElevation

Related methods:

MaterialAutoCompleteTextView_dropDownBackgroundTint

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

dismissDropDown

public void dismissDropDown ()

getDropDownBackgroundTintList

public ColorStateList getDropDownBackgroundTintList ()

Returns the color of the popup dropdown container.

Related XML Attributes:

Returns
ColorStateList

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

onWindowFocusChanged

public void onWindowFocusChanged (boolean hasWindowFocus)

Parameters
hasWindowFocus boolean

setAdapter

public void setAdapter (T adapter)

Parameters
adapter T

setDropDownBackgroundDrawable

public void setDropDownBackgroundDrawable (Drawable d)

Parameters
d Drawable

setDropDownBackgroundTint

public void setDropDownBackgroundTint (int dropDownBackgroundColor)

Sets the color of the popup dropdown container. It will take effect only if the popup background is a MaterialShapeDrawable, which is the default when using a Material theme.

Related XML Attributes:

Parameters
dropDownBackgroundColor int: the popup dropdown container color

setDropDownBackgroundTintList

public void setDropDownBackgroundTintList (ColorStateList dropDownBackgroundTint)

Sets the color of the popup dropdown container. It will take effect only if the popup background is a MaterialShapeDrawable, which is the default when using a Material theme.

Related XML Attributes:

Parameters
dropDownBackgroundTint ColorStateList: the popup dropdown container tint as a ColorStateList object.

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 ()

onDetachedFromWindow

protected void onDetachedFromWindow ()

onMeasure

protected void onMeasure (int widthMeasureSpec, 
                int heightMeasureSpec)

Parameters
widthMeasureSpec int

heightMeasureSpec int