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

AndroidTextview

Android Problem Overview


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

Android Solutions


Solution 1 - Android

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.

Solution 2 - Android

You can do this using this code.

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

Solution 3 - Android

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.

Attributions

All content for this solution is sourced from the original question on Stackoverflow.

The content on this page is licensed under the Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license.

Content TypeOriginal AuthorOriginal Content on Stackoverflow
Questionuser3519555View Question on Stackoverflow
Solution 1 - Androidkrunal patelView Answer on Stackoverflow
Solution 2 - AndroidRobin RoyalView Answer on Stackoverflow
Solution 3 - AndroidEmil AdzView Answer on Stackoverflow