Search code examples
androidandroid-textinputlayoutmaterial-components-androidmaterial-components

How to insert an icon in the beginning of a Material Text Field


I am trying to insert an icon in the beginning of a Material Text Field. I couldn't find anything suitable in material.io's documentation as well.

This is what I am trying to achieve.

Image


Solution

  • Use a TextInputLayout with the app:startIconDrawable

    <com.google.android.material.textfield.TextInputLayout
        android:hint="Select Time"
        app:startIconDrawable="@drawable/ic_add_24px"
        style="@style/Widget.MaterialComponents.TextInputLayout.OutlinedBox">
    
        <com.google.android.material.textfield.TextInputEditText
            ../>
    
    </com.google.android.material.textfield.TextInputLayout>
    

    enter image description here

    Note: it requires the version 1.1.0 of the library.