1、简单的ALertDialog:
Dialog alertDialog = new AlertDialog.Builder(this)
.setTitle("标题")
.setMessage("内容")
.setIcon(R.drawable.ic_launcher).create();
alertDialog.show();
2、带按钮的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 }
} }
相关文章: