在 Android 中,如何在点击时清除 EditText
?
In Android how can I make an EditText
clear when it's clicked?
例如,如果我有一个 EditText
,其中包含一些字符,例如 'Enter Name'
,那么当用户单击它时,这些字符就会消失.
E.g., if I have an EditText
with some characters in, such as 'Enter Name'
, when the user clicks on it these characters disappear.
我不确定你是否在追求这个,但试试这个 XML:
I'm not sure if you are after this, but try this XML:
android:hint="Enter Name"
当输入字段为空、选中或未选中时,它会显示该文本.
It displays that text when the input field is empty, selected or unselected.
或者,如果您希望它完全按照您的描述执行,请在 editText 上分配一个 onClickListener 并使用 setText() 将其设置为空.
Or if you want it to do exactly as you described, assign a onClickListener on the editText and set it empty with setText().
这篇关于如何在点击时清除 EditText?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!