这是第一种方法
public void addcomment() {
// 1.创建弹出式对话框
final AlertDialog.Builder alertDialog = new android.app.AlertDialog.Builder(mActivity); // 系统默认Dialog没有输入框
// 获取自定义的布局
View alertDialogView = View.inflate(mActivity, R.layout.dialog_punchcard_addcomment, null);
final AlertDialog tempDialog = alertDialog.create();
tempDialog.setView(alertDialogView, 0, 0, 0, 0);
//文本输入框
final EditText et_addcomment = (EditText) alertDialogView.findViewById(R.id.et_addcomment);
//取消按钮
Button btn_addcomment_ok = (Button) alertDialogView.findViewById(R.id.btn_addcomment_ok);
btn_addcomment_ok.setOnClickListener(new OnClickListener() {@Override public void onClick(View arg0) {
tempDialog.dismiss();
}
});
//确然按钮
Button btn_addcomment_cancel = (Button) alertDialogView.findViewById(R.id.btn_addcomment_cancel);
btn_addcomment_cancel.setOnClickListener(new OnClickListener() {
@Override public void onClick(View arg0) {
}
});
/** 3.自动弹出软键盘 **/
/*getSystemService()如果在activity里面就可以直接调用,如果在其他的地方要先调用getActivity()*/
tempDialog.setOnShowListener(new OnShowListener() {
public void onShow(DialogInterface dialog) {
InputMethodManager imm = (InputMethodManager) getActivity().getSystemService(Context.INPUT_METHOD_SERVICE);
imm.showSoftInput(et_addcomment, InputMethodManager.SHOW_IMPLICIT);
}
});
tempDialog.show();
}
}
第二种方法 就是将AlertDialog改成Dialog;