Android EditText输入文字小写字母转变成大写字母

采用输入框变化监听

mTvIdCard.addTextChangedListener(object : TextWatcher {
            override fun beforeTextChanged(s: CharSequence?, start: Int, count: Int, after: Int) {
            }

            override fun onTextChanged(s: CharSequence?, start: Int, before: Int, count: Int) {
                mTvIdCard.removeTextChangedListener(this)//解除文字改变事件
                mTvIdCard.setText(s.toString().toUpperCase())//转换
                mTvIdCard.setSelection(s.toString().length)//重新设置光标位置
                mTvIdCard.addTextChangedListener(this)//重新绑
                idCard = mTvIdCard.text.toString().trim()
            }

            override fun afterTextChanged(s: Editable?) {}
        })

你可能感兴趣的:(Android,android,java,kotlin)