0

В поле edit text есть hint. При нажатие на него он подымается вверх, а как сделать так что бы он удалялся при нажатие на него? Что бы он был как placeholder в html.

<com.google.android.material.textfield.TextInputLayout
    android:id="@+id/input_layout_phone"
    android:layout_width="match_parent"
    android:layout_height="wrap_content">

    <EditText
        android:maxLength="15"
        android:drawableTint="@color/colorLogoBlack"
        android:drawableRight="@drawable/ic_profile_con"
        android:textSize="16sp"
        android:id="@+id/input_phone"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:inputType="phone"
        android:hint="@string/phone" />
</com.google.android.material.textfield.TextInputLayout>
1
  • Если вам дан исчерпывающий ответ, отметьте его как принятый нажав на галочку слева от него.
    – Andrew
    21 янв 2021 в 7:36

1 ответ 1

1

Вообще TextInputLayout чаще всего используется в связке с TextInputEditText:

<android.support.design.widget.TextInputLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_margin="@dimen/activity_horizontal_margin"
app:hintEnabled="false">

<android.support.design.widget.TextInputEditText
      android:layout_width="match_parent"
      android:layout_height="wrap_content"
      android:hint="Floating Hint Disabled" />

</android.support.design.widget.TextInputLayout>

ключевым здесь является:

app:hintEnabled="false"

что отключает плавающий хинт. Либо если хотите, то можно использовать editText:

<EditText
    ...
    android:hint="@string/my_hint">
</EditText>

вот туториал по работе с edittext и по TextInputLayout. Чтобы скрыть хинт программно, можно использовать такой способ:

myEditText.setOnFocusChangeListener(new View.OnFocusChangeListener() {
    public void onFocusChange(View v, boolean hasFocus) {
        if (hasFocus)
            myEditText.setHint("");
        else
            myEditText.setHint("Your hint");
    }
});

Ваш ответ

By clicking “Отправить ответ”, you agree to our terms of service and acknowledge you have read our privacy policy.

Всё ещё ищете ответ? Посмотрите другие вопросы с метками или задайте свой вопрос.