Подтвердить что ты не робот

Подсказка по автоопределению AutoCompleteTextView

Я много пробовал, но не могу сделать работу с подсказкой AutoCompleteTextView с поддержкой TextInputLayout.

Возможно или мне нужна внешняя библиотека?

4b9b3361

Ответ 1

Нет.

сама библиотека дизайна достаточно

включают в себя следующее

<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>

Ответ 3

Возможно, немного поздно, но вот трюк:

Создайте следующий класс,

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;
        }
    }
}

Теперь добавьте эти строки в свой файл макета и увидите волшебство

<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>