AppCompatDialog 与 DialogFragment

AppCompatDialog vs DialogFragment

使用最新的 AppCompat

compile "com.android.support:appcompat-v7:22.2.1"

AppCompatDialogDialogFragment 都可用,我更喜欢哪一个?有什么不同或我可以避免的问题吗?

编辑:

我试图通过转换现有的 Dialog 来使用 AppCompatDialogDialogFragment,但在 none 中 getDialog().setTitle("Title") 似乎工作。

2021 年 5 月 17 日更新:

引用自Android Documentation

A dialog is a small window that prompts the user to make a decision or enter additional information. A dialog does not fill the screen and is normally used for modal events that require users to take an action before they can proceed.

You should use a DialogFragment as a container for your dialog. The DialogFragment class provides all the controls you need to create your dialog and manage its appearance, instead of calling methods on the Dialog object.

Using DialogFragment to manage the dialog ensures that it correctly handles lifecycle events such as when the user presses the Back button or rotates the screen. The DialogFragment class also allows you to reuse the dialog's UI as an embeddable component in a larger UI, just like a traditional Fragment (such as when you want the dialog UI to appear differently on large and small screens).

注意:AppCompatDialog 是一个 Dialog 扩展名。


上一个答案(2019 年 11 月 16 日):

DialogFragment and the AppCompatDialog完全不同


根据 Gabriele Mariotti 评论。