Как удалять hint в edit text при нажатии?
В поле 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
→ Ссылка
Вообще 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");
}
});