如何以编程方式更改TextView的图标?

Mar*_* S. 24 android textview

在xml中,您可以在TextView中将文本的左侧,右侧,底部或顶部设置为drawable.有没有办法通过代码设置/更改此drawable?

Ram*_*ran 63

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