method is to define a background XML file in the drawable file.
<?XML version= "1.0" encoding= "Utf-8"?><BitmapAndroid:id= "@+id/toolbar_more_bg"xmlns:android= "Http://schemas.android.com/apk/res/android"android:gravity= "Center"android:src= "@drawable/abc_ic_menu_moreoverflow_mtrl_alpha"Android:tilemode= "Disabled" > </Bitmap>
can be called later. If you have a selector effect on your background, you can solve it as follows:
<?XML version= "1.0" encoding= "Utf-8"?> <selectorxmlns:android= "Http://schemas.android.com/apk/res/android" > <Itemandroid:state_pressed= "true" > <Bitmapandroid:src= "@drawable/toolbar_bg_sel"Android:tilemode= "Disabled"android:gravity= "Top" /> </Item> <Item> <Bitmapandroid:src= "@drawable/toolbar_bg"Android:tilemode= "Disabled"android:gravity= "Top" /> </Item> </selector>
Let background's pictures not change with the size of the view