android 限制EditText输入内容为字母或汉字

val typeFilter = InputFilter { source, start, end, dest, dstart, dend ->
            val p = Pattern.compile("[a-zA-Z|\u4e00-\u9fa5]+")
            val m = p.matcher(source.toString())
            if (!m.matches()) "" else null
        }

        mName?.filters = arrayOf(typeFilter)

说点什么

avatar
  Subscribe  
提醒