触摸edittext时如何使提示消失? [英] how to make hint disappear when edittext is touched?

查看:141
本文介绍了触摸edittext时如何使提示消失?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在我的android应用程序中,有许多EditText字段.而且我遇到了提示问题. 当聚焦EditText时,它不会消失,但是当我开始写东西时,它会消失. 如何解决此问题?因为我需要在触摸EditText字段时消失的提示.

In my application in android are many EditText fields. And I ran into a problem with hint. It is not disappearing when EditText is focused, but it disappears when I start to write something. How can this problem be fixed? Because I need the hint to disappear when the EditText field is touched.

例如:

<EditText
    android:layout_width="260dp"
    android:layout_height="30dp"
    android:ems="10"
    android:inputType="text"
    android:id="@+id/driv_lic_num_reg"
    android:hint="@string/driver_license_numb"
    android:textColor="@color/black"
    android:textColorHint="@color/grey_hint"
    android:background="@drawable/input_field_background"
    android:layout_alignParentTop="true"
    android:layout_centerHorizontal="true"
    android:layout_margin="2dp"
    android:textCursorDrawable="@color/black"
    android:textSize="15dp"
    android:paddingLeft="10dp"
    android:nextFocusDown="@+id/pass_reg"
    android:imeOptions="actionNext"
    android:maxLines="1"
    android:maxLength="50"
    android:focusableInTouchMode="true"/>

推荐答案

仅当您键入任何文本而不是焦点时,提示才会消失.我不认为有任何自动方法可以这样做,可能是我错了.但是,作为一种解决方法,我使用以下代码删除了EditText中焦点的提示

Hint only disappears when you type in any text, not on focus. I don't think that there is any automatic way to do it, may be I am wrong. However, as a workaround I use the following code to remove hint on focus in EditText

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

这篇关于触摸edittext时如何使提示消失?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆