超简单的自定义AlertDialog弹出键盘可以输入的

来源:互联网 发布:js数组删除元素的代码 编辑:程序博客网 时间:2024/06/05 03:18

超简单的自定义AlertDialog弹出键盘可以输入的

demo下载


非常简单,没写什么注释,相信大家一看就明白了

private void showAlertDialog() {final AlertDialog dialog = new AlertDialog.Builder(this).create();dialog.setView(LayoutInflater.from(this).inflate(R.layout.alert_dialog, null));dialog.show();dialog.getWindow().setContentView(R.layout.alert_dialog);Button btnPositive = (Button) dialog.findViewById(R.id.btn_add);Button btnNegative = (Button) dialog.findViewById(R.id.btn_cancel);final EditText etContent = (EditText) dialog.findViewById(R.id.et_content);btnPositive.setOnClickListener(new OnClickListener() {@Overridepublic void onClick(View arg0) {String str = etContent.getText().toString();if (isNullEmptyBlank(str)) {etContent.setError("输入内如不能为空");} else {dialog.dismiss();Toast.makeText(MainActivity.this, etContent.getText().toString(), Toast.LENGTH_LONG).show();}}});btnNegative.setOnClickListener(new OnClickListener() {@Overridepublic void onClick(View arg0) {dialog.dismiss();}});}private static boolean isNullEmptyBlank(String str) {if (str == null || "".equals(str) || "".equals(str.trim()))return true;return false;}
demo下载

1 0