1. project directory
A. In the res directory-create a drawble folder and put the custom image
2. Main. xml
<? XML version = "1.0" encoding = "UTF-8"?> <Br/> <linearlayout xmlns: Android = "http://schemas.android.com/apk/res/android" <br/> Android: Orientation = "vertical" <br/> Android: layout_width = "fill_parent" <br/> Android: layout_height = "fill_parent" <br/> <textview <br/> Android: layout_width = "fill_parent" <br/> Android: layout_height = "wrap_content" <br/> Android: TEXT = "@ string/Hello" <br/> <imagebutton <br/> Android: id = "@ + ID/button" <br/> Android: layout_width = "wrap_content" <br/> Android: layout_height = "wrap_content" <br/> Android: background = "#000000" <br/> Android: src = "@ drawable/SY" <br/> </linearlayout> <br/>
3. Class Code
Package COM. yanse; </P> <p> Import android. app. activity; <br/> Import android. OS. bundle; <br/> Import android. widget. imagebutton; </P> <p> public class Yanse extends activity {</P> <p> private imagebutton image = NULL; <br/> @ override <br/> Public void oncreate (bundle savedinstancestate) {<br/> super. oncreate (savedinstancestate); <br/> setcontentview (R. layout. main); <br/> image = (imagebutton) findviewbyid (R. id. button); <br/>}< br/>}