In Android EditText, how to force writing uppercase?

前端 未结 23 1820
后悔当初
后悔当初 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

    Based on the accepted answer, this answer does the same, but in Kotlin. Just to ease copypasting :·)

    private fun EditText.autocapitalize() {
        val allCapsFilter = InputFilter.AllCaps()
        setFilters(getFilters() + allCapsFilter)
    }
    

提交回复
热议问题