How to Get EditText maxLength setting in code

后端 未结 7 1181
鱼传尺愫
鱼传尺愫 2020-12-01 12:34

I would like to see the maxLength of an EditText at run time to be able to make a text display decision.
Is that possible?

Here is a de

7条回答
  •  陌清茗
    陌清茗 (楼主)
    2020-12-01 13:09

    From api 21 you can do it like that:

    for (InputFilter filter : mEditText.getFilters()) {
            if (filter instanceof InputFilter.LengthFilter) {
                ((InputFilter.LengthFilter) filter).getMax());
            }
    }
    

    I hope this helps someone.

提交回复
热议问题