How to Get EditText maxLength setting in code

后端 未结 7 1175
鱼传尺愫
鱼传尺愫 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:11

    Kind of complicated, but I don't know of any other approach. I hope it works (not tested):

    XmlResourceParser parser = getResources().getLayout(R.layout.theLayout);
    String namespace = "http://schemas.android.com/apk/res/android";
    int maxLength = parser.getAttributeIntValue(namespace, "maxLength", 12);
    

提交回复
热议问题