I've tried a lot, but can't make work an AutoCompleteTextView
float hint using the TextInputLayout
from support.
It's possible or I need to use an external library?
I've tried a lot, but can't make work an AutoCompleteTextView
float hint using the TextInputLayout
from support.
It's possible or I need to use an external library?
No .
include like this
<android.support.design.widget.TextInputLayout
android:id="@+id/til_id"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="125dp"
>
<AutoCompleteTextView
android:id="@+id/auto_text"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:hint="Id"
android:singleLine="true"/>
</android.support.design.widget.TextInputLayout>
It's maybe a little bit late but here is the trick:
Create the following Class,
public class AutoCompleteTextInputLayout extends TextInputLayout {
private boolean mIsHintSet;
private CharSequence mHint;
public AutoCompleteTextInputLayout(Context context) {
super(context);
}
public AutoCompleteTextInputLayout(Context context, AttributeSet attrs) {
super(context, attrs);
}
@Override
public void addView(View child, int index, ViewGroup.LayoutParams params) {
if (child instanceof EditText) {
mHint = ((EditText) child).getHint();
}
super.addView(child, index, params);
}
@Override
protected void onDraw(Canvas canvas) {
super.onDraw(canvas);
if (!mIsHintSet && ViewCompat.isLaidOut(this)) {
setHint(null);
EditText editText = getEditText();
if (editText == null) {
return;
}
CharSequence currentEditTextHint = editText.getHint();
if (!TextUtils.isEmpty(currentEditTextHint)) {
mHint = currentEditTextHint;
editText.setHint("");
}
setHint(mHint);
mIsHintSet = true;
}
}
}
Now Add this lines to your layout file and see the magic
<com.example.AutoCompleteTextInputLayout
android:id="@+id/text_input_autocomplete"
android:layout_width="match_parent"
android:layout_height="wrap_content">
<AutoCompleteTextView
android:id="@+id/autocomplete_tv"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:singleLine="true"
android:textColorHint="@color/textColorDarkHint"/>
</com.example.AutoCompleteTextInputLayout>