Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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?

like image 496
Marcin S. Avatar asked Sep 09 '25 17:09

Marcin S.


1 Answers

TextView textView = (TextView)findViewById(R.id.myTxtView);
textView.setCompoundDrawablesWithIntrinsicBounds(
  R.drawable.icon, //left
  0, //top
  0, //right
  0);//bottom
like image 61
Ram kiran Pachigolla Avatar answered Sep 13 '25 09:09

Ram kiran Pachigolla