天天看點

動态設定TextView四周的圖檔

Android

中有時需動态設定TextView四周的

drawble

圖檔,這個時候就需要調用

setCompoundDrawables(left, top, right, bottom)

方法,四個參數類型都是

Drawable

類型。

示例代碼如下:

Drawable img_on, img_off;
Resources res = getResources();
img_off = res.getDrawable(R.drawable.btn_strip_mark_off);
//調用setCompoundDrawables時,必須調用Drawable.setBounds()方法,否則圖檔不顯示
img_off.setBounds(, , img_off.getMinimumWidth(), img_off.getMinimumHeight());
btn.setCompoundDrawables(img_off, null, null, null); //設定左圖示
           

原文

http://blog.sina.com.cn/s/blog_4b93170a0102e1m9.html