Thanks to the access model for Java members and Google developers who have left a small loophole, this can be achieved with a simple subclass that repeats the minimal source code:
package android.support.design.widget; import android.content.Context; import android.graphics.Rect; import android.util.AttributeSet; public final class TextInputLayoutEx extends TextInputLayout { private final int mDefaultPadding = __4DP__; private final Rect mTmpRect = new Rect(); public TextInputLayoutEx(Context context, AttributeSet attrs) { super(context, attrs); } @Override protected void onLayout(boolean changed, int left, int top, int right, int bottom) { super.onLayout(changed, left, top, right, bottom); if (isHintEnabled() && mEditText != null) { final Rect rect = mTmpRect; ViewGroupUtils.getDescendantRect(this, mEditText, rect); mCollapsingTextHelper.setCollapsedBounds( rect.left + mDefaultPadding, getPaddingTop(), rect.right - mDefaultPadding, bottom - top - getPaddingBottom()); mCollapsingTextHelper.recalculate(); } } }
Here we put the new class in the same package, which gives access to mCollapsingTextHelper with package-level visibility, and then repeats part of the code from the original onLayout method, which controls the positioning of the field name. The __4DP__ value is a 4dp value converted to pixels, I'm sure everyone has a utility method for this.
In your xml layout, just switch from android.support.design.widget.TextInputLayout to android.support.design.widget.TextInputLayoutEx so that your layout looks like this:
<android.support.design.widget.TextInputLayoutEx android:layout_width="match_parent" android:layout_height="wrap_content" android:hint="Mobile"> <android.support.design.widget.TextInputEditText android:layout_width="match_parent" android:layout_height="wrap_content" android:drawableLeft="@drawable/ic_phone_black_24dp" android:drawablePadding="4dp"/> </android.support.design.widget.TextInputLayoutEx>
And the result

It currently works for com.android.support:design:25.3.1
source share