EditText getHint() returns null when using design support library

后端 未结 3 1091
情歌与酒
情歌与酒 2020-12-17 17:19

When using EditText in combination with Design lib\'s (ver 22.2.1) TextInputLayout getting hint programmatically returns null.

I\'m trying to append asterisk \'*\'

3条回答
  •  挽巷
    挽巷 (楼主)
    2020-12-17 17:52

    Actually the hint moves to the parent view TextInputLayout that surrounds the EditText view:

    You can get the hint like this:

    android.support.design.widget.TextInputLayout parent = (android.support.design.widget.TextInputLayout) yourEditText.getParent();
    String hint = parent.getHint().toString();
    

    And if you want to add * make it like this:

    parent.setHint(parent.getHint() + "*");
    

    Happy codding! :)

提交回复
热议问题