1

我正在更新一个仍然支持 Android 2.0 的旧应用程序。有一段新代码我真的很想建立一个自定义对话框 - 但所有文档都在谈论使用 DialogFragments。我没有在我的应用程序中的任何地方使用 Fragment,那么如何让 FragmentManager 让我显示对话框?

或者有人可以指向我的文档以获取 pre-Fragment 对话框支持吗?

4

2 回答 2

0

You should use the Android Support Library v4 and also convert all the activities where you need to display the dialog from Activity to FragmentActivity. In this way you don't have to modify your activities but you can use the DialogFragment.

于 2013-09-11T15:28:11.657 回答
0

您仍然可以在不使用片段的情况下以相同的方式创建对话框。

例如:

AlertDialog.Builder builder = new AlertDialog.Builder(context);
    builder.setMessage(R.string.dialog_fire_missiles)
           .setPositiveButton(R.string.fire, new DialogInterface.OnClickListener() {
               public void onClick(DialogInterface dialog, int id) {
                   // FIRE ZE MISSILES!
               }
           })
           .setNegativeButton(R.string.cancel, new DialogInterface.OnClickListener() {
               public void onClick(DialogInterface dialog, int id) {
                   // User cancelled the dialog
               }
           });
    // Create the AlertDialog object and return it
    return builder.create();

我强烈建议您停止支持 2.0 并开始支持 2.2 和您的最小 sdk 目标,以便您可以切换到使用片段,因为这是现在做事的首选方式

于 2013-09-10T15:47:23.270 回答