How to programmatically set maxLength in Android TextView?

后端 未结 11 1772
心在旅途
心在旅途 2020-11-29 17:06

I would like to programmatically set maxLength property of TextView as I don\'t want to hard code it in the layout. I can\'t see any set

11条回答
  •  执笔经年
    2020-11-29 17:39

    As João Carlos said, in Kotlin use:

    editText.filters += InputFilter.LengthFilter(10)
    

    See also https://stackoverflow.com/a/58372842/2914140 about some devices strange behaviour.

    (Add android:inputType="textNoSuggestions" to your EditText.)

提交回复
热议问题