Android创建AlertDialog对话框

来源:互联网 发布:java企业级项目开发 编辑:程序博客网 时间:2024/05/15 10:56

实现三个按键的默认对话框


引入对话框类:

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

结果:


0 0
原创粉丝点击