In this Example How to attached drawable to textview in android.
A quick dig through the documentation for TextView lead me to the setCompoundDrawableWithIntrinsicBounds() method which is a method of attaching drawables to a TextView.
See more update android
Using Xml Code:
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:drawableTop="@drawable/ic_launcher"
android:gravity="center"
android:text="Hello" />
You can Drawable to any side of textview like top,bottom,right,left.
android:drawableBottom="@drawable/ic_launcher"
android:drawableTop="@drawable/ic_launcher"
android:drawableRight="@drawable/ic_launcher"
android:drawableLeft="@drawable/ic_launcher"
Using Java Code:
@Override
public void onCreate( Bundle savedInstanceState )
{
super.onCreate( savedInstanceState );
setContentView( R.layout.main );
TextView tv = (TextView) findViewById( R.id.textView );
tv.setCompoundDrawablesWithIntrinsicBounds( 0,
R.drawable.ic_launcher, 0, 0 );
}