首页 > 技术文章 > 关于dialog的一点知识

likeshu 2016-04-13 18:01 原文

  一般我们比较常用的就是AlertDialog,这个一般也不直接构造,而是用系统提供的builder构造器去构造一个dialog。

  

 AlertDialog.Builder builder =  new AlertDialog.Builder(context);
 builder.setCancelable(true).setTitle("标题").setMessage("内容").setIcon(new BitmapDrawable(context.getResources())).setNegativeButton().setPositiveButton();
 builder.create();

  如上,这是比较常用的。在API21上面可以直接setView,这个方法听起来比较厉害。

  如果需要自定义布局的话,也可以,

  

                    AlertDialog dialog = new AlertDialog.Builder(context)
                        .create();
                    dialog.show();
                    dialog.setCanceledOnTouchOutside(true);
                    dialog.getWindow().setContentView(
                        R.layout.dialog_item_list_conversation);

 

推荐阅读