TextInputEditText 将输入的字符计为 2 个字符
TextInputEditText count the entered character as 2 characters
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))
}
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))
}