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

时间:2012-10-02 04:47:52

标签: android textview

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

1 个答案:

答案 0 :(得分:63)

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