末尾带有十字 (x) 按钮的 EditText
有没有办法像iPhone一样在android编辑框中添加x图形 这样,通过单击该 x 图形,它可以清除编辑框中的所有值
有没有办法收听天气我触摸编辑文本的特定部分 谢谢
Is there any way to add the x-graphics in the android Editbox like the of iPhone
So that by clicking on that x graphic it can clear all the values in the Editbox
Is there any way to listen weather i touch a specific part of an edit text
Thank you
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
是的,有一种方法可以实现这一目标。
定义一个像这样的RelativeLayout。
现在会发生什么。 ImageButton 绘制在 EditText 之上。我们将其右边缘设置为等于 EditText 的右边缘,以便使其显示在右侧。
现在,您必须为 ImageButton 分配一个 OnCLickListener ,并使用 if 重写方法将 EditTexts 文本设置为这样的空字符串。
现在,
我们只是告诉 ImageViews OnClickListener 在单击时重置 EditTexts 文本。就这么简单。 ;)
当然,我的示例使用的图像不是很美观,但您可以自己微调图像。这个原理是有效的。
Yes there is a way to achieve this.
Define a RelativeLayout like this one.
Now what happens. The ImageButton gets drawn on top of the EditText. We set its right edge to be equal to the right edge of the EditTexts in order to get it appear on the right side.
Now you have to assign your ImageButton an OnCLickListener with if overridden method to just set the EditTexts text to a empty string like that.
}
Now here we simply tell our ImageViews OnClickListener to reset our EditTexts text upon a click. Simple as that. ;)
Of course my example uses not very aesthetic images but you can fine tune the images yourself. The principle works.
您可以下载它,它的工作方式与 iPhone
https://github.com/GhOsTTT/editTextXbutton
You can download it, it works like iPhone
https://github.com/GhOsTTT/editTextXbutton