First, give your TextView
an ID so you can find it in your Activity
:
<TextView
android:id="@+id/textView"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="20dip"
android:drawableTop="@drawable/new" />
Second, in your Activity
find your TextView
and get the compound drawables in your onCreate
method after calling setContentView
:
TextView textView = (TextView) findViewById(R.id.textView);
// Left, top, right, bottom drawables.
Drawable[] compoundDrawables = textView.getCompoundDrawables();
// This is the top drawable.
Drawable topCompoundDrawable = compoundDrawables[1];