TextInputEditText对输入的最大字符数有限制,例如30。当您输入@字符时,必须将其计数为2,即如果您只输入@,则您可以输入不超过15个字符。如何实现这样的算法?
找到解决方案,与textChanges((RxJava 一起运行
fun charDoubleLength(string:String, charDouble: Char, editText: EditText, maxLengthLine: Int){
val charCount = string.filter { char ->
char == charDouble
}.count()
val maxLengthEditText= maxLengthLine - charCount
editText.filters =
arrayOf<InputFilter>(InputFilter.LengthFilter(maxLengthEditText))
}