TextInputLayout animation overlaps the text when the text is set programmatically

后端 未结 4 852
無奈伤痛
無奈伤痛 2020-12-29 08:04

I am using TextInputLayout with the design support library 22.2.1.

I set the value of the EditText programmatically, and when the

4条回答
  •  遥遥无期
    2020-12-29 08:16

    I ran into this issue recently while using DialogFragment. To solve, simply disable the hint animation if you have a value in the field before you set the field value. The order is important.

    For example,

    TextInputLayout layout = (TextInputLayout) findViewById(R.id.text_layout);
    TextInputEditText edit = (TextInputEditText) findViewById(R.id.text_edit);
    
    String fieldValue = "Something";
    
    layout.setHintAnimationEnabled(fieldValue == null);
    edit.setText(fieldValue);
    

    This way the layout does not initiate the animation when the text is set. You can also watch for text changes and enable it again when the field is empty.

提交回复
热议问题