Left Icon in TextInputLayout

Juliatzin picture Juliatzin · Jun 19, 2015 · Viewed 43.1k times · Source

I'm trying to add an Left Icon to my TextInputLayout, but text get over the Icon. When I add a padding, everything move together.

I tried with

 android:drawableLeft="@drawable/ic_store_white_48dp"
 android:drawablePadding="50dp"
 android:drawableStart="@drawable/ic_store_white_48dp"

But it is not working ! I should implement a LinearLayout horizontal for each row, but I would like to be sure there is no easier way to do it

Here is my code layout:

        <android.support.design.widget.TextInputLayout
            android:id="@+id/til_calle"
            android:layout_width="match_parent"
            android:layout_height="wrap_content">


            <EditText
                android:id="@+id/et_calle"
                android:layout_width="fill_parent"
                android:layout_height="wrap_content"
                android:drawableLeft="@drawable/ic_store_white_48dp"
                android:drawablePadding="50dp"
                android:drawableStart="@drawable/ic_store_white_48dp"
                android:hint="Calle"
                android:inputType="text" />

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

Answer

Jared Burrows picture Jared Burrows · Feb 27, 2016

Make sure you are using the latest Design library, all you need for both Design and AppCompat is:

compile 'com.android.support:design:23.2.0'

Try using both the Design's library TextInputLayout and AppCompat's AppCompatEditText.

<android.support.design.widget.TextInputLayout
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:layout_gravity="center"
    android:textColor="@android:color/white"
    android:textColorHint="@color/loginHint">

    <android.support.v7.widget.AppCompatEditText
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:imeOptions="actionNext"
        android:inputType="textEmailAddress|textNoSuggestions"
        android:minWidth="350dp"
        android:drawableLeft="@drawable/ic_store_white_48dp"
        android:drawableStart="@drawable/ic_store_white_48dp"
        android:textColor="@android:color/white"
        android:textColorHint="@color/loginHint"
        android:textCursorDrawable="@null"
        app:backgroundTint="@android:color/white"/>
</android.support.design.widget.TextInputLayout>