The business needs to be provided in the control code drawableLeft
, drawableRight
, drawableTop
, drawableBottom
properties.
We know that in xml method set as follows:
android:drawableLeft="@drawable/xxxxx"
However, in the code No setDrawableLeft and the like. How to do it?
Do not worry, api provides us with a setCompoundDrawables(left,top,right,bottom);
way for developers to set the appropriate boundary picture.
The method of operation is very simple, as shown in the following code:
// 使用代码设置drawableleft
Drawable drawable = getResources().getDrawable(
R.drawable.ic_qaa_top_icon);
// 这一步必须要做,否则不会显示。
drawable.setBounds(0, 0, drawable.getMinimumWidth(),
drawable.getMinimumHeight());
Button.setCompoundDrawables(null, null, drawable, null);