Setbackgroundresource () or when you set the Android:background property in XML, define your background as XML bitmap, as follows:
<!--? XML version= "1.0" encoding= "Utf-8"?--><bitmap xmlns:android= "http://schemas.android.com/apk/res/ Android "android:id=" @id/toolbar_bg_bmp "android:src=" @drawable/toolbar_bg "android:tilemode=" Disabled "Android: gravity= "Top" ></bitmap>
The call is as follows:
Imagebutton.setbackgroundresource (r.drawable.toolbar_bg_bmp)
Or
If the background image has a variety of states, you can also refer to Toolbar_bg_selector.xml:
<!--? XML version= "1.0" encoding= "Utf-8"?--><selector xmlns:android= "http://schemas.android.com/apk/res/ Android "> <item android:state_pressed=" true "> <bitmap android:src=" @drawable/toolbar_bg_sel " Android:tilemode= "Disabled" android:gravity= "top" > </bitmap></item> <item> <bitmap android:src= "@drawable/toolbar_bg" android:tilemode= "Disabled" android:gravity= "top" > </ Bitmap></item></selector>
Android_ setting Backgroud stretching issues