同时提示editText中的提示和文本 [英] Hint and Text in editText at same time

查看:62
本文介绍了同时提示editText中的提示和文本的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我只需要一个editText,我可以在其中同时设置Text和hint.例如我希望用户输入诸如user#1234之类的editText字符串此字符串中的user#应该是文本,之后的数字将有所不同,以便当用户尝试输入光标时1234应该显示为提示,而#后面应该显示1234,而当用户键入字符时1234提示将消失.

I just need an editText in which i can set Text and hint at the same time. e.g i want user to enter in editText string like user#1234 in this string user# should be text after that numbers will vary so that 1234 should be show as hint when user try to enter cursor will go after # and 1234 hint will gone when user type a character.

请指导我该怎么做.

谢谢

推荐答案

在Android的默认 EditText 中这是不可能的,但是如果要以任何方式实现此目的,则必须花点功夫.

This is not possible in the Android's default EditText but if want to achieve this any how, you will have to work a bit.

您可以使用名为 Masked-EditText 的库.阅读文档并了解如何使用它来解决您的目的.希望能有所帮助.

You can use this library called Masked-EditText. Read the documentation and understand how you can use it to solve your purpose. Hope that helps.

我还有另外一个技巧,您绝对可以使用.在编辑文本上实现 onChangeListener .每次调用它时,都要运行一个函数.该函数应获取 editText 中的文本并获取子字符串(前5个字符).如果子字符串与"user#"匹配,则不执行任何操作.否则将editText中的文本替换为"user#".容易哈哈!

I've got one more trick that you can definitely use. Implement an onChangeListener on the edit text. Every time it is called, run a function. The function should get the text in the editText and get the substring (first 5 char). If the substring matches "user#" then do not do anything. Else replace the text in editText with "user#". Easy hah!

这篇关于同时提示editText中的提示和文本的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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