'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 1:[1]

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.

Solution 2:[2]

Solution 3:[3]

step 1: copy required Text field

Material text field doc : https://material.io/components/text-fields/android#using-text-fields

enter image description hereenter image description here enter image description here

step 2: select text field -> search "draw" -> Click drawableLeft icon

enter image description here

step 3: Select or Add icon (I'll select vector icon)

enter image description here enter image description here enter image description here enter image description here

Select icon before Finish enter image description here

Select icon and click OK enter image description here

Done :) enter image description here

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1
Solution 2 dominicoder
Solution 3 Lojith Vinsuka Abeysinghe