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?
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.
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.
Now you can simply do input. setError(..) for new error and input. setErrorEnabled(false) to remove it.
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>
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With