58

I want to add icon at the left side of the textView.How can I do that?

user3519555
  • 599
  • 1
  • 4
  • 5

3 Answers3

125

You can use:

android:drawableLeft="@drawable/ic_launcher"

and you can also put padding between drawable and textview by

android:drawablePadding="2dp"

If you always want an icon to appear before the text, it is recommended to use drawableStart instead of drawableLeft since many languages are not read left to right.

ExcellentSP
  • 1,440
  • 2
  • 15
  • 37
krunal patel
  • 2,198
  • 1
  • 10
  • 11
75

You can do this using this code.

TextView textView = (TextView) findViewById(R.id.myTxtView);
textView.setCompoundDrawablesWithIntrinsicBounds(R.drawable.icon, 0, 0, 0);
Ravindra Kushwaha
  • 7,428
  • 13
  • 49
  • 95
Robin Royal
  • 1,678
  • 1
  • 16
  • 28
7

You can use this in your XML file:

android:drawableLeft

For your TextView and specify a drawable there your want to present on the left side of it.

Emil Adz
  • 39,787
  • 36
  • 133
  • 182