实现三个按键的默认对话框
引入对话框类:
import android.app.AlertDialog;
自定义实现对话框:
public void okCancelAlertDialog(){
AlertDialog dialog = new AlertDialog.Builder(this)
.setIcon(R.drawable.ic_launcher)
.setTitle(R.string.red)
.setPositiveButton("OK",new DialogInterface.OnClickListener() { //设置左边的按键
@Override
public void onClick(DialogInterface arg0, int arg1) {
}
})
.setNeutralButton("details", new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int whichButton) {
/* 中键事件 */
}
})
.setNegativeButton("Cancel",new DialogInterface.OnClickListener(){ //设置右边的按键
@Override
public void onClick(DialogInterface arg0, int arg1) {
// TODO Auto-generated method stub
}
})
.create();//创建
dialog.show();//显示
}
结果: