android 自定义对话框

android开发常常用到自定义弹出对话框,AlertDialog 通常是这样使用:

AlertDialog.Buider builder = new Builder(MainActivity.this);

builder.setTitle("对话框标题");

builder.setMessage("对话框内容");

builder.setPositiveButton(DialogInterface dialog , int which){

dialog.dismiss();

builder.setPositiveButton("确认", new OnClickListener() {

   @Override

   public void onClick(DialogInterface dialog, int which) { 

   dialog.dismiss();   

   }  

});

  builder.setNegativeButton("取消", new OnClickListener() { 

  @Override

   public void onClick(DialogInterface dialog, int which) {   

   dialog.dismiss();

   } 

 }); 

 builder.create().show();

}

也可以把 一个Layout 布局转成View 组件来显示到对话框上, 实例:

    AlertDialog.Builder dialog = new AlertDialog.Builder(MainActivity.this);
                dialog.setTitle("消息列表:");
                LayoutInflater inflater =  LayoutInflater.from(MainActivity.this);
                View view =inflater.inflate(R.layout.dialog_layout, null);
                dialog.setView(view); 
                dialog.show();

 

更多可以参考下 其他博主的文章

 

posted @ 2013-10-11 13:25  一个学渣  阅读(244)  评论(0编辑  收藏  举报

 

CSDNGitHub 联系邮箱:aikongmeng@gmail.com


Copyright 2008-2019 Government All Rights Reserved