5

I have added a drawableLeft in and EditText enclosed in TextInputLayout. The position of hint of TextInputLayout is according to the text position(From left i.e. next to drawableLeft) as:

enter image description here

But I want the position of hint as below. enter image description here

Thank you.

BST Kaal
  • 2,993
  • 6
  • 34
  • 52
  • First of all, which language? Second, what have you tried? Show us some code... – Fusseldieb Oct 17 '16 at 10:35
  • I dnt think so that the language concerns. I have tried `hintTextAppearance` but it only changes the size/color of the text. I have tried giving **left padding=0dp** to `TextInputLayout` itself but that doesn't work. – BST Kaal Oct 17 '16 at 10:40
  • 1
    I've a solution for that on [this post](http://stackoverflow.com/questions/39530520/adding-a-drawableleft-to-an-edittext-shifts-the-hint-towards-right-if-edittext). – Mike M. Oct 17 '16 at 22:22
  • 1
    Thank you @MikeM. , I have tried a workaround which is working for me, but definitely not a good one, so I will surely try your answer. – BST Kaal Oct 18 '16 at 12:04
  • 1
    @MikeM. your solution works great. – BST Kaal Feb 05 '17 at 13:46

2 Answers2

1

There's no way to currently do this. If you check out the TextInputLayout source, you can see that the hint takes the parent's compound padding into account. The CollapsingTextHelper is not part of the layout's public API, so you can't change its behavior easily.

Your best bet is to change your requirement for this padding or use some sort of custom layout to reach a compromise between effort and effect.

npace
  • 4,218
  • 1
  • 25
  • 35
  • Thank you so much, I was just wondering if there is any official(documented by android developers) way to do this. – BST Kaal Oct 17 '16 at 10:45
  • Look around in the source - I didn't find anything exposing the hint helper's padding logic, unfortunately. I suggest removing the post envelope icon or moving it to a separate `ImageView` to the left of the `TextInputLayout` so that your texts line up correctly. – npace Oct 17 '16 at 10:49
  • I have already tried using a separate `ImageView` but the issues is, whether I have to position the `EditText` after the `ImageView` or give it some extra padding left to appear after `ImageView` but the issue will be same, the hint will show according to the `EditText` text. – BST Kaal Oct 17 '16 at 10:53
  • Well if you are willing to do a dirty hack, you can use an `ImageSpan` to render the icon as the first "word" of your EditText - but you have to make sure the user can't delete it. This is going to lead to a lot of debugging and headaches, though... – npace Oct 17 '16 at 11:03
0

Try below code

<android.support.design.widget.TextInputLayout
        android:layout_width="match_parent"
        android:layout_marginTop="20dp"
        android:layout_height="54dp"
        android:gravity="bottom"
        android:paddingTop="4dp"
        android:clipToPadding="false"  // above 3 lines are important
        android:id="@+id/emailWrapper"
        app:hintTextAppearance="@style/floatingLabel">

        <EditText
            android:layout_width="match_parent"
            android:layout_height="54dp"
            android:paddingLeft="17dp"
            android:paddingRight="17dp"
            android:id="@+id/txtEmail"
            android:singleLine="true"
            android:inputType="textEmailAddress"
            android:hint="@string/emailPlaceholder"
            android:text="a@a.com"
            android:background="@drawable/btn_empty_stroke" />

    </android.support.design.widget.TextInputLayout>

Check it also : Android: How to change the textsize in an EditText field?

Community
  • 1
  • 1
Manikandan K
  • 911
  • 9
  • 21