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

Increase margin for TextView compound drawable

I have the following code

 <TextView
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:background="@drawable/edit_search_background"
    android:padding="8dp"
    android:drawableStart="@drawable/info"
    android:text="@string/msg_decode_notice"/>

It looks like this:

Notice

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

The problem is that the margin from the edge of the field to the icon differs from the margin from the icon to the text. How can I increase the indentation on the right without resorting to the ImageView + TextView? I try to make my layout as flat as possible

>Solution :

You can try using the android:drawablePadding attribute to specify the padding between the drawable (the icon) and the text. You can also use the android:paddingStart and android:paddingEnd attributes to specify the padding of the text field.

<TextView
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:background="@drawable/edit_search_background"
    android:padding="8dp"
    android:drawableStart="@drawable/info"
    android:drawablePadding="16dp"
    android:paddingStart="24dp"
    android:text="@string/msg_decode_notice"/>

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