Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

How to position drawable start icon at the start of the material text input layout

How to position the drawable start icon at the start of text input layout

<com.google.android.material.textfield.TextInputLayout
                    android:layout_width="match_parent"
                    android:layout_height="wrap_content"
                    android:hint="New Password"
                    app:expandedHintEnabled="true"
                    app:hintTextAppearance="@style/text_medium_12_size"
                    app:errorTextAppearance="@style/text_regular_10_size"
                    app:boxStrokeColor="@color/main_theme_color"
                    app:startIconDrawable="@drawable/ic_baseline_lock"
                    style="@style/Widget.Design.TextInputLayout">

                    <com.google.android.material.textfield.TextInputEditText
                        android:layout_width="match_parent"
                        android:layout_height="wrap_content"
                        android:paddingStart="0dp"
                        android:paddingEnd="0dp"
                        android:drawablePadding="0dp"
                        style="@style/text_medium_12_size"
                        android:importantForAutofill="no"/>

                </com.google.android.material.textfield.TextInputLayout>

The result of the above code is show in image below

enter image description here

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

But I want to achieve like the drawable start icon at start of the text input layout start which is show as image attched below

enter image description here

I need to remove the extra start space between drawable start icon of the text input layout. Is is possible to achieve it?

>Solution :

remove app:startIconDrawable="@drawable/ic_baseline_lock" in TextInputLayout

and add android:drawableStart="@mipmap/ic_baseline_lock" in TextInputEditText

<com.google.android.material.textfield.TextInputLayout
                    android:layout_width="match_parent"
                    android:layout_height="wrap_content"
                    android:hint="New Password"
                    app:expandedHintEnabled="true"
                    app:hintTextAppearance="@style/text_medium_12_size"
                    app:errorTextAppearance="@style/text_regular_10_size"
                    app:boxStrokeColor="@color/main_theme_color"
                    app:startIconDrawable="@drawable/ic_baseline_lock" // remove this line
                    style="@style/Widget.Design.TextInputLayout">

                    <com.google.android.material.textfield.TextInputEditText
                        android:layout_width="match_parent"
                        android:layout_height="wrap_content"
                        android:paddingStart="0dp"
                        android:paddingEnd="0dp"
                        android:drawableStart="@mipmap/ic_baseline_lock" //add this line
                        android:drawablePadding="0dp"
                        style="@style/text_medium_12_size"
                        android:importantForAutofill="no"/>

                </com.google.android.material.textfield.TextInputLayout>
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading