您的位置:首页 > 移动开发 > Android开发

Android创建AlertDialog对话框

2014-08-11 10:35 387 查看
实现三个按键的默认对话框

引入对话框类:

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();//显示

}

结果:
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: