英文:
In Android EditText, is there a way to force every character to be lowercase?
问题
我在这里找到了很多关于使EditText显示大写字符的解决方案,但是,有没有一种方法来实现相反的效果,并将其限制为仅小写字符?
使用 android:digits="abcdefghijklmnpqrstuvwxyz"
虽然“起作用”,但它会简单地忽略不在列表中的字符,而没有任何反馈。我希望即使用户输入大写字符,它也会被转换为小写字符。
它可以忽略数字,没问题。
英文:
I found a lot of solutions here to make EditText display characters in caps, however, is there a way to do the opposite and limit it to lowercase characters only?
Using android:digits="abcdefghijklmnpqrstuvwxyz"
"works" but it simply ignores characters not in the list with no feedback. I want it so that even when the user inputs an uppercase character, it is converted to a lowercase character.
<br>It can ignore numbers, that is fine.
答案1
得分: 1
以下是翻译好的内容:
Max链接了一个Java解决方案,但这里是一个Kotlin版本的:
edit_text.filters += object : AllCaps() {
override fun filter(
source: CharSequence,
start: Int,
end: Int,
dest: Spanned,
dstart: Int,
dend: Int
): CharSequence {
return source.toString().toLowerCase()
}
}
英文:
Max linked to a Java solution but here is a kotlin one:
edit_text.filters += object : AllCaps() {
override fun filter(
source: CharSequence,
start: Int,
end: Int,
dest: Spanned,
dstart: Int,
dend: Int
): CharSequence {
return source.toString().toLowerCase()
}
}
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论