android - TextInputLayout hint overlap issue -


i'm using textinputlayout android design library show label on edittext.

the problem when start activity edittext hint (label) text overlaps actual text (for second) , returns own place (at top of edittext).

to illustrate issue recorded short sample video: https://youtu.be/gy0czcyggxu

here activity.xml:

<linearlayout   android:layout_width="match_parent"   android:layout_height="wrap_content"   android:layout_margin="16dp"   android:orientation="vertical">  <android.support.design.widget.textinputlayout     android:id="@+id/firstnametextinputlayout"     android:layout_width="match_parent"     android:layout_height="wrap_content"     android:layout_margintop="8dp">    <edittext       android:id="@+id/firstnameedittext"       android:layout_width="match_parent"       android:layout_height="wrap_content"       android:hint="@string/first_name"       android:inputtype="textcapwords"       android:textcolor="@color/textprimary"       android:textcolorhint="@color/textsecondary"       android:textsize="16sp"       android:theme="@style/customedittext"/> </android.support.design.widget.textinputlayout>   <android.support.design.widget.textinputlayout     android:layout_width="match_parent"     android:layout_height="wrap_content"     android:layout_margintop="24dp">    <edittext       android:id="@+id/lastnameedittext"       android:layout_width="match_parent"       android:layout_height="wrap_content"       android:hint="@string/last_name"       android:inputtype="textcapwords"       android:textcolor="@color/textprimary"       android:textcolorhint="@color/textsecondary"       android:textsize="16sp"       android:theme="@style/customedittext"/> </android.support.design.widget.textinputlayout> 

i came cheap workaround , bug.

subclass textinputlayout
see code addview()
if have text set in text view when inflated set hint collapsed , prevent animation. code performs workaround temporarily set text until state set during setup. bonus there code makes sure hint gets drawn in case there 1 layout pass.

public class textinputlayout extends android.support.design.widget.textinputlayout {  public textinputlayout(context context) {     super(context); }  public textinputlayout(context context, attributeset attrs) {     super(context, attrs); }  @suppresslint("drawallocation") @override protected void onlayout(final boolean changed, final int left, final int top, final int right, final int bottom) {     if (viewcompat.islaidout(this)) {         super.onlayout(changed, left, top, right, bottom);     } else {         // workaround terrible logic onlayout gets called before view flagged laid out.         // normal textinputlayout depending on islaidout when onlayout called , failing check prevents initial drawing         // if there multiple layout passes doesn't broken         post(new runnable() {             @suppresslint("wrongcall")             @override             public void run() {                 textinputlayout.super.onlayout(changed, left, top, right, bottom);             }         });     } }  @override public void addview(view child, int index, viewgroup.layoutparams params) {     if (child instanceof edittext) {         edittext edittext = (edittext) child;         if (stringutils.isempty(edittext.gettext().tostring())) {             edittext.settext("  "); // set filler text initial state of floating title collapsed             super.addview(child, index, params);             edittext.settext(""); // set blank cause hint animate in in case user sets text             // prevents hint being drawn on text set programmatically before state determined             return;         }     }     super.addview(child, index, params); } 

}


Comments

Popular posts from this blog

c# - Validate object ID from GET to POST -

node.js - Custom Model Validator SailsJS -

php - Find a regex to take part of Email -