TextInputLayout and AutoCompleteTextView
A little late, but yes, you'll have to roll your own implementation. The good news is that this is fairly straightforward. Here's how TextInputEditText
was implemented:
https://android.googlesource.com/platform/frameworks/support.git/+/master/design/src/android/support/design/widget/TextInputEditText.java
Accordingly, here's what TextInputAutoCompleteTextView
might look like.
public class TextInputAutoCompleteTextView extends AppCompatAutoCompleteTextView {
public TextInputAutoCompleteTextView(Context context) {
super(context);
}
public TextInputAutoCompleteTextView(Context context, AttributeSet attrs) {
super(context, attrs);
}
public TextInputAutoCompleteTextView(Context context, AttributeSet attrs, int defStyleAttr) {
super(context, attrs, defStyleAttr);
}
@Override
public InputConnection onCreateInputConnection(EditorInfo outAttrs) {
final InputConnection ic = super.onCreateInputConnection(outAttrs);
if (ic != null && outAttrs.hintText == null) {
// If we don't have a hint and our parent is a TextInputLayout, use it's hint for the
// EditorInfo. This allows us to display a hint in 'extract mode'.
final ViewParent parent = getParent();
if (parent instanceof TextInputLayout) {
outAttrs.hintText = ((TextInputLayout) parent).getHint();
}
}
return ic;
}
}
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>