天天看点

安卓在代码中设置TextView的drawableLeft、drawableRight、drawableTop、drawableBottom

安卓在代码中设置textview的drawableleft、drawableright、drawabletop、drawablebottom

textview的xml文件

在代码中如果要修改drawableright设置的图片可以使用api

void android.widget.textview.setcompounddrawables(drawable left,

drawable top,

drawable right, drawable bottom)

drawable可以通过 drawable rightdrawable = getresources().getdrawable(r.drawable.icon_new); 得到。

但是api提示,setcompounddrawables() 调用的时候,drawable对象必须调用setbounds(int left, int top, int right, int bottom)方法,于是我们加一行代码就可以了。

整体代码如下:

继续阅读