Android: how to add an icon on the left side of a TextView

I want to add an icon on the left side of a textView. How can i do this?

+12
android android-textview
source share
3 answers

You can do this using this code.

TextView textView = (TextView) findViewById(R.id.myTxtView); textView.setCompoundDrawablesWithIntrinsicBounds(R.drawable.icon, 0, 0, 0); 
+28
source share

You can use:

 android:drawableLeft="@drawable/ic_launcher" 

and you can also put a pad between drawable and textview by

 android:drawablePadding="2dp" 

If you always want the icon to appear in front of the text, it is recommended to use drawableStart instead of drawableLeft since many languages โ€‹โ€‹are not read from left to right.

+38
source share

You can use this in your xml file:

 android:drawableLeft 

For your TextView and specify the selection that you want to display on the left side.

+4
source share

All Articles