Xamarin Android.App.DialogFragment已过时 [英] Xamarin Android.App.DialogFragment Obsolete

查看:279
本文介绍了Xamarin Android.App.DialogFragment已过时的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

TL; DR 是否有人知道Xamarin中为什么 Android.App.DialogFragment 已过时,更重要的是,推荐使用哪种类?

TL;DR Does anyone know why Android.App.DialogFragment is obsolete in Xamarin and, more importantly, what class is recommended instead?

更多信息:

我在Xamarin.Android应用中收到以下警告:

I'm getting the following warnings in my Xamarin.Android app:

警告CS0618'DialogFragment'已过时:'该类在此android平台中已过时'警告CS0618'Activity.FragmentManager'已过时:'deprecated'

Warning CS0618 'DialogFragment' is obsolete: 'This class is obsoleted in this android platform' Warning CS0618 'Activity.FragmentManager' is obsolete: 'deprecated'

来自以下代码:

using Android.App;

void onClick(int pos) {
    DialogFragment newFragment = new UsernameDialogFragment(_scans[pos]);
    newFragment.Show(_activity.FragmentManager, "dialog");
}

public class UsernameDialogFragment : DialogFragment {
    public override Dialog OnCreateDialog(Bundle savedInstanceState) {
        var builder = new AlertDialog.Builder(Activity);
        // Build the dialog...
        return builder.Create();
    }
}

请注意,我使用的是 Android.App.DialogFrament 类,而不是 Android.Support.V4.App 中的类. onClick 方法是 RecyclerView.Adapter 的一部分.

Note that I am using the Android.App.DialogFrament class, not the one in Android.Support.V4.App. The onClick method is part of a RecyclerView.Adapter.

对于Xamarin这样的问题,令我感到沮丧的是,几乎没有足够的文档.IntelliSense警告不建议使用其他API,对于Google搜索"DialogFrament已过时",除论坛的帖子过旧,建议使用过时的API,最糟糕的是, DialogFragment API文档甚至没有显示该类已过时!

What is so frustrating to me about Xamarin issues like this is that there is almost never sufficient documentation. The IntelliSense warnings don't recommend an alternative API, a Google search for "DialogFrament is obsolete" turns up nothing Xamarin-related except this old forum post recommending to use the obsolete API, and worst of all, the DialogFragment API documentation doesn't even show that the class is obsolete!

某些版本信息:

Xamarin.Forms NuGet:v3.1.0.697729
Visual Studio 2017:v15.8.1
目标框架:Android 9.0(P)
最低Android版本:Android 5.0(API级别21-Lollipop)
目标Android版本:Android 9.0(API级别27-Oreo)

Xamarin.Forms NuGet: v3.1.0.697729
Visual Studio 2017: v15.8.1
Target Framework: Android 9.0 (P)
Minimum Android version: Android 5.0 (API Level 21 - Lollipop)
Target Android version: Android 9.0 (API Level 27 - Oreo)

推荐答案

看一下Android文档,它在Android P ie/API级别28中已弃用.假定Xamarin文档最终将得到更新.Android P刚刚于2018年8月6日发布,但我建议您始终阅读链接的官方 Android文档.

Look at the Android documentation, it is deprecated in Android Pie / API Level 28. Assuming the Xamarin documentation will get updated eventually as Android P was just released August 6, 2018, but I would recommend always reviewing the linked official Android documentation.

re: https://developer.android.com/reference/android/app/DialogFragment

该类已在API级别28中弃用.

This class was deprecated in API level 28.

使用支持库DialogFragment在所有设备上实现一致的行为并访问生命周期.

Use the Support Library DialogFragment for consistent behavior across all devices and access to Lifecycle.

所以,是的,支持库是未来的(嗯...是未来),现在是 Android.Support.V4.App.Fragment ,但是这些库已被支持库所取代.Android扩展库( AndroidX )和所有将来的更新将在这些AndroidX库中,并且仅将错误/安全性修复程序应用于支持库.

So, yes, the support libraries are the future (well...were the future), Android.Support.V4.App.Fragment for right now, but those are being superseded by the Android extension libraries (AndroidX) and all future updates will be in those AndroidX libraries with only bug/security fixes being applied to the support libraries.

28.0.0的稳定版本将成为打包为android.support的最终功能版本.所有后续功能版本将仅以androidx打包的工件形式提供.

The stable release of 28.0.0 will be the final feature release packaged as android.support. All subsequent feature releases will only be made available as androidx-packaged artifacts.

re: https://android-developers.googleblog.com/2018/05/hello-world-androidx.html

这篇关于Xamarin Android.App.DialogFragment已过时的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆