DialogFragment Class 在 Android P 中弃用
DialogFragment Class Deprecated in Android P
Android 文档给出了以下警告。
This class was deprecated in API level P.
Use the Support Library DialogFragment for consistent behavior across all devices and access to Lifecycle.
这是否意味着我作为开发人员唯一的改变是导入 android.support.v4.app.DialogFragment
而不是旧的 android.app.DialogFragment
?
Google 鼓励所有开发人员从普通的 DialogFragment 转移到相同 class 的支持版本,当然你仍然可以使用已弃用的版本,但如果 Google 建议支持版本,你为什么不呢?
只需将导入语句从 android.app.DialogFragment
更改为 android.support.v4.app.DialogFragment
。
此外,如果您使用的是普通片段的弃用版本,请考虑更改所有导入。
更新
如果您使用的是全新的 AndroidX 库而不是旧的支持库,请将其更改为 androidx.fragment.app.DialogFragment
但请注意您在代码中使用 DialogFragment 的方式,因为您还必须迁移到新的androidx.fragment.app.FragmentActivity
.
Android 文档给出了以下警告。
This class was deprecated in API level P. Use the Support Library DialogFragment for consistent behavior across all devices and access to Lifecycle.
这是否意味着我作为开发人员唯一的改变是导入 android.support.v4.app.DialogFragment
而不是旧的 android.app.DialogFragment
?
Google 鼓励所有开发人员从普通的 DialogFragment 转移到相同 class 的支持版本,当然你仍然可以使用已弃用的版本,但如果 Google 建议支持版本,你为什么不呢?
只需将导入语句从 android.app.DialogFragment
更改为 android.support.v4.app.DialogFragment
。
此外,如果您使用的是普通片段的弃用版本,请考虑更改所有导入。
更新
如果您使用的是全新的 AndroidX 库而不是旧的支持库,请将其更改为 androidx.fragment.app.DialogFragment
但请注意您在代码中使用 DialogFragment 的方式,因为您还必须迁移到新的androidx.fragment.app.FragmentActivity
.