AlertDialog可以有多种功能模式,比如单选多选等等,但是呢要和自己app整体风格统一或者要修改布局什么的就不是太方便,所以一般情况下最好还是使用自定义布局,扩展性灵活性比较高
AlertDialog.Builder builder = new AlertDialog.Builder(context); final AlertDialog dialog = builder.create(); View dialogView = View.inflate(context, R.layout.dialog, null); dialog.setView(dialogView); dialog.show(); EditText inputView = (EditText) dialogView.findViewById(R.id.input_view); TextView TextView = (TextView) dialogView.findViewById(R.id.text_view); Button confirmBtn = (Button) dialogView.findViewById(R.id.btn_confirm); btnLogin.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { dialog.dismiss(); } });