Android在代码中设置控件的drawableLeft/Right/Top/Bottom
2015-01-04 13:04
113 查看
根据业务的需要,要在代码中设置控件的drawableLeft,drawableRight,drawableTop,drawableBottom属性。
我们知道在xml中设置的方法为:android:drawableLeft="@drawable/xxxxx";
但是在代码中并没有相关的setDrawableLeft等方法。怎么办呢?别担心,api为我们提供了一个setCompoundDrawables(left,top,right,bottom);方法,供开发人员设置相应的边界图片。
操作方法十分简单,如下代码所示:
ok,完成
我们知道在xml中设置的方法为:android:drawableLeft="@drawable/xxxxx";
但是在代码中并没有相关的setDrawableLeft等方法。怎么办呢?别担心,api为我们提供了一个setCompoundDrawables(left,top,right,bottom);方法,供开发人员设置相应的边界图片。
操作方法十分简单,如下代码所示:
// 使用代码设置drawableleft Drawable drawable = getResources().getDrawable( R.drawable.ic_qaa_top_icon); // / 这一步必须要做,否则不会显示. drawable.setBounds(0, 0, drawable.getMinimumWidth(), drawable.getMinimumHeight()); getTv_title().setCompoundDrawables(null, null, drawable, null);
ok,完成
相关文章推荐
- Android在代码中设置控件的drawableLeft,drawableRight,drawableTop,drawableBottom
- Android在代码中设置控件的drawableLeft,drawableRight,drawableTop,drawableBottom。
- Android在代码中设置控件的drawableLeft,drawableRight,drawableTop,drawableBottom。
- 【Android】代码中设置drawableLeft|Top|Right|Bottom
- Android控件设置——动态View的drawableLeft/ drawableRight/drawableTop/drawableBottom
- 动态设置android:drawableLeft|Right|Top|Bottom
- 安卓在代码中设置TextView的drawableLeft、drawableRight、drawableTop、drawableBottom
- android 动态设置android:drawableLeft|Right|Top|Bottom
- TextView 代码设置drawableLeft、drawableRight、drawableTop、drawableBottom
- 动态设置android:drawableLeft|Right|Top|Bottom
- 动态设置android:drawableLeft|Right|Top|Bottom
- 动态设置android:drawableLeft|Right|Top|Bottom
- 动态设置 android:drawableTop|Right|Left|Bottom
- Android 设置 drawableLeft|Right|Top|Bottom
- Android动态设置android:drawableLeft|Right|Top|Bottom 并根据分辨率自适应
- 安卓在代码中设置TextView的drawableLeft、drawableRight、drawableTop、drawableBottom
- 安卓在代码中设置TextView的drawableLeft、drawableRight、drawableTop、drawableBottom
- 安卓在代码中设置TextView的drawableLeft、drawableRight、drawableTop、drawableBottom
- 【Android】TextView动态设置android:drawableLeft|Right|Top|Bottom,SetColor
- 在代码中设置TextView的drawableLeft、drawableRight、drawableTop、drawableBottom