Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Android: how to add Icon at the left side of the TextView [duplicate]

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

like image 955
user3519555 Avatar asked Aug 13 '14 06:08

user3519555


3 Answers

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.

like image 102
krunal patel Avatar answered Sep 28 '22 21:09

krunal patel


You can do this using this code.

TextView textView = (TextView) findViewById(R.id.myTxtView);
textView.setCompoundDrawablesWithIntrinsicBounds(R.drawable.icon, 0, 0, 0);
like image 34
Robin Royal Avatar answered Sep 28 '22 20:09

Robin Royal


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.

like image 39
Emil Adz Avatar answered Sep 28 '22 19:09

Emil Adz