MaterialAutoCompleteTextView

public class MaterialAutoCompleteTextView


A special sub-class of android.widget.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 android.widget.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 .

Summary

Public fields

final float
int
ColorStateList

Public constructors

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

Public methods

void
ColorStateList

Returns the color of the popup dropdown container.

CharSequence
float

Returns the elevation of the dropdown popup.

int

Returns the color of the default selected popup dropdown item.

ColorStateList

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

void
onWindowFocusChanged(boolean hasWindowFocus)
void
<T extends ListAdapter & Filterable> setAdapter(T adapter)
void
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(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(String[] stringArray)

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

void
setSimpleItems(int stringArrayResId)

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

void

Protected methods

void
void
void
onMeasure(int widthMeasureSpec, int heightMeasureSpec)

Public fields

popupElevation

public final float popupElevation

simpleItemSelectedColor

public int simpleItemSelectedColor

simpleItemSelectedRippleColor

public ColorStateList simpleItemSelectedRippleColor

Public constructors

MaterialAutoCompleteTextView

public MaterialAutoCompleteTextView(Context context)

MaterialAutoCompleteTextView

public MaterialAutoCompleteTextView(
    Context context,
    AttributeSet attributeSet
)

MaterialAutoCompleteTextView

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

Public methods

dismissDropDown

public void dismissDropDown()

getDropDownBackgroundTintList

public ColorStateList getDropDownBackgroundTintList()

Returns the color of the popup dropdown container.

ref com.google.android.material.R.styleable#MaterialAutoCompleteTextView_dropDownBackgroundTint

getHint

public CharSequence getHint()

getPopupElevation

public float getPopupElevation()

Returns the elevation of the dropdown popup.

ref com.google.android.material.R.styleable#MaterialAutoCompleteTextView_android_popupElevation

getSimpleItemSelectedColor

public int getSimpleItemSelectedColor()

Returns the color of the default selected popup dropdown item.

ref com.google.android.material.R.styleable#MaterialAutoCompleteTextView_simpleItemSelectedColor

getSimpleItemSelectedRippleColor

public ColorStateList getSimpleItemSelectedRippleColor()

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

ref com.google.android.material.R.styleable#MaterialAutoCompleteTextView_simpleItemSelectedRippleColor

onWindowFocusChanged

public void onWindowFocusChanged(boolean hasWindowFocus)

setAdapter

public void <T extends ListAdapter & Filterable> setAdapter(T adapter)

setDropDownBackgroundDrawable

public void setDropDownBackgroundDrawable(Drawable d)

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.

ref com.google.android.material.R.styleable#MaterialAutoCompleteTextView_dropDownBackgroundTint

Parameters
int dropDownBackgroundColor

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.

ref com.google.android.material.R.styleable#MaterialAutoCompleteTextView_dropDownBackgroundTint

Parameters
ColorStateList dropDownBackgroundTint

the popup dropdown container tint as a ColorStateList object.

setOnItemSelectedListener

public void setOnItemSelectedListener(OnItemSelectedListener listener)

setRawInputType

public void setRawInputType(int type)

setSimpleItemSelectedColor

public void setSimpleItemSelectedColor(int simpleItemSelectedColor)

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

ref com.google.android.material.R.styleable#MaterialAutoCompleteTextView_simpleItemSelectedColor

Parameters
int simpleItemSelectedColor

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.

ref com.google.android.material.R.styleable#MaterialAutoCompleteTextView_simpleItemSelectedRippleColor

Parameters
ColorStateList simpleItemSelectedRippleColor

the ripple color state list

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.

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.

showDropDown

public void showDropDown()

Protected methods

onAttachedToWindow

protected void onAttachedToWindow()

onDetachedFromWindow

protected void onDetachedFromWindow()

onMeasure

protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec)