26

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?

Cœur
  • 37,241
  • 25
  • 195
  • 267
Marcin S.
  • 11,161
  • 6
  • 50
  • 63
  • Does this answer your question? [Programmatically set left drawable in a TextView](https://stackoverflow.com/questions/6931900/programmatically-set-left-drawable-in-a-textview) – General Grievance Sep 01 '22 at 19:15

1 Answers1

68
TextView textView = (TextView)findViewById(R.id.myTxtView);
textView.setCompoundDrawablesWithIntrinsicBounds(
  R.drawable.icon, //left
  0, //top
  0, //right
  0);//bottom
Andrew M.
  • 9
  • 1
  • 4
Ram kiran Pachigolla
  • 20,897
  • 15
  • 57
  • 78