How to programmatically change TextView Drawable in Android is part of an issues I have solved in one of my projects. So I have decided to document it for future reference.
It might also help someone.
Drawable topIcon = getResources().getDrawable( R.drawable.ic_favorite_border_white_24dp); TextView.setCompoundDrawablesWithIntrinsicBounds(null, topIcon, null, null);
The image resource in the drawable folder is converted to a Drawable object.
The drawable object is passed as a parameter to TextView
setCompoundDrawablesWithIntrinsicBound(left, top, right, bottom)
You can pass null value to drawable positions you are not interested in.