Android sometimes need to dynamically set the control around the drawble picture, this time need to call Setcompounddrawables (left, top, right, bottom), four parameter types are drawable
Button Inherits TextView, so you can use the same Setup method
method One. XML Mode
<TextViewAndroid:id= "@+id/booktitle"Android:layout_width= "Match_parent"Android:layout_height= "Wrap_content"Android:drawableleft= "@drawable/checkmark"Android:drawableright= "@drawable/checkmark"Android:drawabletop= "@drawable/checkmark"android:gravity= "Center_vertical"Android:textstyle= "Bold"android:textsize= "20dip"Android:maxlines= "1"android:ellipsize= "End"/>
method Two. Java Code
== res.getdrawable (r.drawable.btn_strip_mark_off); // the Drawable.setbounds () method must be called when Setcompounddrawables is called, otherwise the picture does not display img_off.setbounds(0, 0null NULL NULL // Set left icon