Marcin S.
Marcin S.

Reputation: 11191

How to change an icon of the TextView programmatically?

In the xml you can set a drawable to the left, right, bottom or top of the text in TextView. Is there a way to set / change this drawable through a code?

Upvotes: 26

Views: 17445

Answers (1)

Ram kiran Pachigolla
Ram kiran Pachigolla

Reputation: 21191

TextView textView = (TextView)findViewById(R.id.myTxtView);
textView.setCompoundDrawablesWithIntrinsicBounds(
  R.drawable.icon, //left
  0, //top
  0, //right
  0);//bottom

Upvotes: 68

Related Questions