如何在点击时清除 EditText? [英] How to clear an EditText on click?

查看:20
本文介绍了如何在点击时清除 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屋!

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