在 Android 中的 EditText/TextView 中设置临时文本?
我正在寻找一个简单的用户名/密码输入表单,我想知道是否可以模仿许多网站提供的功能,即文本输入中的临时字符串,显示该字段的用途。本质上,我需要这样的东西:
当用户尚未专注于文本输入时,它应该以不同的格式显示“USERNAME”。当用户将焦点放在文本字段上时,该字段将被清除并设置焦点并更改样式。有没有办法轻松做到这一点?
I'm looking to build a simple input form for username/password, and I was wondering if it was possible to mimic the functionality that many websites offer, namely a temporary string within a text input displaying what the field's purpose is. Essentially, I need something like this:
When the user hasn't yet focused in on the text input, it should display "USERNAME" in a different format. When the user has focused in on the text field, the field is cleared and focus is set and the style is changed. Is there a way to do this easily?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
查看 edittext 的属性 - 有一个“提示”属性可以做到这一点。
android:hint="输入用户名"
look at the properties of the edittext - there is a "hint" property that does just that.
android:hint="Enter Username"
您只需在特定的编辑文本中设置 android:hint="USERNAME" 即可。
当您在该编辑文本中写入内容时,它会清除提示并设置您的文本。简单...
You can simply set android:hint="USERNAME" in a particular edittext.
When you will write something in that edittext, it will clear the hint and set your text.Simple...