是否有用于输入文本、列表等的内置对话框……比如内置的首选项屏幕?

Are there built in dialogs for input for text, lists, etc... like builtin preference screens?

在首选项片段中,当您单击 EditTextPreference 或 ListPreference 或其他项目时...它会自动打开一个对话框,允许输入或选择,具体取决于您将其设置为什么。

如果您不使用 PrefFrag.... 而是编写自己的输入屏幕,是否有任何内置对话框可以调用来执行此操作,或者我们是否必须从头开始创建自己的对话框?

是的,您必须从头开始创建它。嗯.. 不完全是从头开始,因为你有 AlertDialog.BuilderDialogFragmentProgressDialogDatePickerDialogTimePickerDialog。要创建您的 dialogs.Please,请查看 Dialog documentations

但与首选项不同的是,xml 元素不会神奇地为您提供这些对话框。

你可以试试this。它包含许多标准对话框,如输入文本、列表项和其他。

你必须自己构建它们,虽然大部分代码可以很容易地从这篇文章中复制,稍作改动:http://developer.android.com/guide/topics/ui/dialogs.html

那里包括从列表中选择一个项目。对于文本字段,您需要做一些稍微不同的事情。这是一个例子。在 Activity:

中使用它
    //First, set these variable to what you want
    String title = "ENTER A TITLE HERE";
    AlertDialog.Builder builder = new AlertDialog.Builder(this);
    builder.setTitle(title);

    // Set up the input
    final EditText input = new EditText(this);
    input.setInputType(InputType.TYPE_CLASS_TEXT);
    builder.setView(input);

    // Set up the buttons
    builder.setPositiveButton("OK", new DialogInterface.OnClickListener() {
        @Override
        public void onClick(DialogInterface dialog, int which) {
            String text = input.getText().toString();
            //text is the String the user inputted, use it for what you need here
        }
    });
    builder.setNegativeButton("Cancel", new DialogInterface.OnClickListener() {
        @Override
        public void onClick(DialogInterface dialog, int which) {
            //This means the user hit Cancel instead of OK
        }
    });

    AlertDialog dialog = builder.create();
    dialog.setCanceledOnTouchOutside(true);
    dialog.show();