您的位置:首页 > 其它

给Button或TextView设置drawableLeft图片(左图标)

2013-01-18 13:45 471 查看
1、XML方式

<Button android:drawableLeft="@drawable/btn_strip_mark_on"></Button>

复制代码
2、JAVA代码

Drawable img_on, img_off;

Resources res = getResources();

img_off = res.getDrawable(R.drawable.btn_strip_mark_off);

// 调用setCompoundDrawables时,必须调用Drawable.setBounds()方法,否则图片不显示

img_off.setBounds(0, 0, img_off.getMinimumWidth(), img_off.getMinimumHeight());

btn.setCompoundDrawables(img_off, null, null, null); //设置左图标

复制代码
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: