TextInputLayout animation overlaps the text when the text is set programmatically

后端 未结 4 850
無奈伤痛
無奈伤痛 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:07

    Currently the only way to avoid this behavior is to add the EditText programmatically.

    1. Create a TextInputLayout without the EditText. Programmatically or via XML inflation - doesn't matter, but it has to be empty.
    2. Create the EditText and set its text to whatever you need.
    3. Add the EditTExt to the TextInputLayout.

    Here's an example:

    TextInputLayout til = (TextInputLayout) findViewById(R.id.til);
    til.setHint(R.string.hint);
    
    EditText et = new EditText(getContext());
    et.setText(value);
    
    til.addView(et);
    

    UPDATED 21/08/2015 WITH DESIGN LIBRARY V23:

    With the design support library v23 you can disable the animation:

    Just use the setHintAnimationEnabled method:

    textInputLayout.setHintAnimationEnabled(boolean)
    

    Here the issue on Google Tracker.

提交回复
热议问题