一、在XML中定义好要显示的AlertDialog的布局

二、在代码中创建alertdialog 对象

AlertDialog dialog = new AlertDialog.Builder(this).create();

调用show方法显示

 dialog.show();

三、设置 AlertDialog窗体的大小

dialog.getWindow().setGravity(Gravity.CENTER);

dialog.getWindow().setLayout((int)(width/1.5), LayoutParams.WRAP_CONTENT);

点击输入框时用来显示软键盘
dialog.getWindow().clearFlags(WindowManager.LayoutParams.FLAG_ALT_FOCUSABLE_IM);

显示布局
dialog.getWindow().setContentView(roleAlertLayout);

当单击外层布局时隐藏软键盘

layout.setOnClickListener(new OnClickListener() {

public void onClick(View v) {
// TODO Auto-generated method stub
InputMethodManager imm = (InputMethodManager)getSystemService(PageRole.this.INPUT_METHOD_SERVICE);
imm.hideSoftInputFromWindow(roleEdit.getWindowToken(), 0);
}
});

 

posted on 2014-10-10 23:40  自由自在0  阅读(763)  评论(0编辑  收藏  举报