1. Create a new project
2. Open Main.xml in res/layout

3. Add a ImageButton to layout file main.xml

4. Set the Background property to an image in your project

5. Note the value for the imageButton ID

6. In ButtonActivity.java add the following code to the OnCreate() method. Make sure that R.id.ImageButton01 matches your imageButton’s ID.
final ImageButton button = (ImageButton) findViewById(R.id.android_button);
button.setOnClickListener(new OnClickListener() {
public void onClick(View v) {
// Perform action on clicks
Toast.makeText(HelloFormStuff.this, "Beep Bop", Toast.LENGTH_SHORT).show();
}
});
7. Run application and select the image, “Beep Boo” message appears: Screen shot











0 comments:
Post a Comment