if you set the drawable in the XML, you won't be able to access it like you can with an ImageView
's getDrawable()
. Instead, omit it from your XML and do it in your Activity/Fragment
:
TextView tv = (TextView) view.findViewById(R.id.textView1);
AnimationDrawable d = (AnimationDrawable) getResources().getDrawable(R.drawable.ic_launcher);
tv.setCompoundDrawables(d, null, null, null);
d.start();
Provided your drawable ic_launcher
can be animated like an AnimationDrawable, this should start the animation. Call d.stop()
to cease animation.