Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

TextInputLayout and AutoCompleteTextView

I'm using TextInputLayout in my Android app to achieve that neat floating label effect for my input fields. I know that I should be using the TextInputEditText as well to allow hints to be displayed when in landscape mode and the input are fills the entire screen.

However, in some of my input fields I have got autocompletion going on using AutoCompleteTextView (which IMO has a really inconsistent name to it – “TextView” instead of “EditText” – but that's another story) and that obviously inherits directly from EditText. Thus it doesn't have the same functionality as TextInputEditText brings.

So I'm wondering if there's a way to achieve the same hint-in-landscape functionality (without making my own TextInputAutoCompleteTextView implementation, that is) and to also avoid the lint warnings that are produced. Am I missing something here? I suppose I get that they didn't make custom versions of all direct and indirect subclasses of EditText for this specific thing, so am I expected to make my own?

like image 726
sindrenm Avatar asked Sep 10 '16 23:09

sindrenm


People also ask

What is AutoCompleteTextView?

An editable text view that shows completion suggestions automatically while the user is typing. The list of suggestions is displayed in a drop down menu from which the user can choose an item to replace the content of the edit box with.

What is a TextInputLayout?

Android TexInputLayout extends LinearLayout. The primary use of a TextInputLayout is to act as a wrapper for EditText(or its descendant) and enable floating hint animations. Rule of Thumb : TextInputLayout should wrap TextInputEditText instead of the normal EditText.

How do I remove TextInputLayout error?

Now you can simply do input. setError(..) for new error and input. setErrorEnabled(false) to remove it.


1 Answers

Now, with AndroidX you don't need customise something.
Need just add material component style (was added in 1.1.0-alpha06, see release notes).

<com.google.android.material.textfield.TextInputLayout     android:layout_width="match_parent"     android:layout_height="wrap_content"     android:hint="Example TextInputLayout">      <androidx.appcompat.widget.AppCompatAutoCompleteTextView     style="@style/Widget.MaterialComponents.AutoCompleteTextView.FilledBox"     android:layout_width="match_parent"     android:layout_height="wrap_content"/>  </com.google.android.material.textfield.TextInputLayout>  
like image 56
R00We Avatar answered Sep 23 '22 01:09

R00We