简体   繁体   English

如何在编辑文本中输入内容后更改文本视图颜色

[英]how to change textview color upon entering something in edittext

when the user has put something according to written on the enter image description here text I want that text color to change like in this image当用户根据在此处输入图像描述上写的文字输入内容时,我希望该文本颜色像这张图片一样改变

If this is a password checker then there is probably already a library for this.如果这是一个密码检查器,那么可能已经有一个用于此的库。 Otherwise, you could use addTextChangedListener() to listen for text changes in your EditText then call setTextColor() to change the of the EditText.否则,您可以使用 addTextChangedListener() 来侦听 EditText 中的文本更改,然后调用 setTextColor() 来更改 EditText。

after addTextChangedListener() in OnTextChanged method add this and can set color在 OnTextChanged 方法中的 addTextChangedListener() 之后添加这个并可以设置颜色

if (charSequence.toString().contains("^[0-9]*$")) {//numbers
                        
}
if (charSequence.toString().contains("^[a-z]*$")){//lower case
    
}
if (charSequence.toString().contains("^[A-Z]*$")){//uppercase
    
}
if (charSequence.toString().length()==9){//ten characters
    
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM