如何在单击时清除EditText? [英] How to clear an EditText on click?
本文介绍了如何在单击时清除EditText?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
在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?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文