Android:AlertDialog对话框

时间:2021-06-17 14:02:02

1、简单的ALertDialog:

Android:AlertDialog对话框

Dialog alertDialog = new AlertDialog.Builder(this)
.setTitle("标题")
.setMessage("内容")
.setIcon(R.drawable.ic_launcher).create();
alertDialog.show();

2、带按钮的ALertDialog

Android:AlertDialog对话框

public class MainActivity extends Activity {

    okListener oklistener=new okListener();
noListener nolistener =new noListener();
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.demo);
Dialog alertDialog = new AlertDialog.Builder(this).setTitle("标题")
.setMessage("内容").setIcon(R.drawable.ic_launcher)
.setPositiveButton("确定", oklistener)
.setNegativeButton("取消", nolistener)
.create();
alertDialog.show();
} public class okListener implements DialogInterface.OnClickListener{ @Override
public void onClick(DialogInterface dialog, int which) {
// TODO Auto-generated method stub }
} public class noListener implements DialogInterface.OnClickListener{ @Override
public void onClick(DialogInterface dialog, int which) {
// TODO Auto-generated method stub }
} }

相关文章:

Android详细的对话框AlertDialog.Builder使用方法

Android:实现退出确认对话框