在上一项目上需要对TextView在xml文件中设置的drawableLeft的图片进行更改,查询了资料好久也没有找到解决办法,如下代码所示:
1 commentTV.setCompoundDrawables(drawable, null, null, null);
后来又经过在stackoverflow,sourceforge等网站上进行询问,才发现是因为缺少了对drawable的边界进行处理,修改后的可起作用代码如下:
1 Drawable drawable = getResources().getDrawable( 2 R.drawable.edit_icon); 3 drawable.setBounds(0, 0, drawable.getMinimumWidth(), 4 drawable.getMinimumHeight()); 5 commentTV.setCompoundDrawables(drawable, null, null, null);
解决了一个小问题,不敢独享喜悦,故发篇小博客来纪念一下,也希望能够帮到后来遇到相似问题的同行,使少走弯路~