1、布局文件
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:gravity="center" >
<ImageButton
android:id="@+id/exit"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="#0000"
android:src="@drawable/img04"/>
</RelativeLayout>
2、取消、中立和确定按钮
ImageButton button1 = (ImageButton)findViewById(R.id.exit);//获取“退出”按钮
//为退出按钮添加单击事件监听器
button1.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
AlertDialog alert = new AlertDialog.Builder(MainActivity.this).create();
alert.setIcon(R.drawable.img04);
alert.setTitle("退出?");
alert.setMessage("真的不能再愉快的玩一下吗?");
//添加取消按钮
alert.setButton(DialogInterface.BUTTON_NEGATIVE, "不",new OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
}
});
//添加确定按钮
alert.setButton(DialogInterface.BUTTON_POSITIVE, "是的", new OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
}
});
}
});