gpt4 book ai didi

android - AppCompatDialog 与 DialogFragment

转载 作者:行者123 更新时间:2023-12-02 16:46:25 25 4
gpt4 key购买 nike

使用最新的AppCompat

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

有可用的 AppCompatDialogDialogFragment 我应该选择哪一个,有什么差异或问题可以避免吗?

编辑:

我尝试通过转换现有的Dialog来使用AppCompatDialogDialogFragment,但没有使用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 日):

DialogFragmentAppCompatDialog完全不同。

<小时/>

根据Gabriele Mariotti评论。

关于android - AppCompatDialog 与 DialogFragment,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32228738/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com