动态设置android:drawableLeft|Right|Top|Bottom
2014-04-09 10:06
435 查看
Android中有时需动态设置控件四周的drawble图片,这个时候就需要调用 setCompoundDrawables(left, top, right, bottom),四个参数类型都是drawable
Button继承TextView,所以可以采用相同的设置方法
方法一.XML方式
方法二.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); //设置左图标
Button继承TextView,所以可以采用相同的设置方法
方法一.XML方式
方法二.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); //设置左图标
相关文章推荐
- 动态设置android:drawableLeft|Right|Top|Bottom
- 动态设置 android:drawableTop|Right|Left|Bottom
- 动态设置android:drawableLeft|Right|Top|Bottom
- 动态设置android:drawableLeft|Right|Top|Bottom
- android 动态设置android:drawableLeft|Right|Top|Bottom
- Android动态设置android:drawableLeft|Right|Top|Bottom 并根据分辨率自适应
- 动态设置android:drawableLeft|Right|Top|Bottom
- 【Android】TextView动态设置android:drawableLeft|Right|Top|Bottom,SetColor
- 动态设置android:drawableLeft|Right|Top|Bottom
- 动态设置android:drawableLeft|Right|Top|Bottom
- 动态设置android:drawableLeft|Right|Top|Bottom
- android 动态设置android:drawableLeft|Right|Top|Bottom
- Android控件设置——动态View的drawableLeft/ drawableRight/drawableTop/drawableBottom
- android 动态设置drawableTop,drawableLeft,drawableRight,drawableBottom.
- Android在代码中设置控件的drawableLeft,drawableRight,drawableTop,drawableBottom。
- 动态设置Button的drawableLeft | Top |Right |Bottom
- 绝对能用-动态设置textview的drawableleft、drawableright、drawabletop、drawablebottom
- Android在代码中设置控件的drawableLeft/Right/Top/Bottom
- 【Android】代码中设置drawableLeft|Top|Right|Bottom
- Android 设置 drawableLeft|Right|Top|Bottom