我会选择使用 AlertDialog
:
AlertDialog dialog = new AlertDialog.Builder(this)
.setView(getLayoutInflater().inflate(R.layout.custom_dialog, null))
.create();
为了监听用户界面事件:View view = getLayoutInflater().inflate(R.layout.custom_dialog, null);
Button btn = (Button)view.findViewById(R.id.the_id_of_the_button);
btn.setOnClickListener(blah blah);
AlertDialog dialog = new AlertDialog.Builder(this)
.setView(view)
.create();
您可以在Android对话框文档中查看:
Dialog类是对话框的基类,但是应避免直接实例化Dialog。而是使用以下子类之一: