In Android EditText, how to force writing uppercase?

前端 未结 23 1828
后悔当初
后悔当初 2020-11-27 12:28

In my Android application I have different EditText where the user can enter information. But I need to force user to write in uppercase letters. Do you know a

23条回答
  •  星月不相逢
    2020-11-27 13:01

    Simple kotlin realization

    fun EditText.onlyUppercase() {
        inputType = InputType.TYPE_CLASS_TEXT or InputType.TYPE_TEXT_FLAG_CAP_CHARACTERS
        filters = arrayOf(InputFilter.AllCaps())
    }
    

    PS it seems that filters is always empty initially

提交回复
热议问题