与YouTube发布商专用的片段类型不兼容 [英] Incompatible fragment type with the Youtube Player for Publishers

查看:64
本文介绍了与YouTube发布商专用的片段类型不兼容的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图在我们的androidx应用程序中添加最新的Youtube Player for Publishers v2.1.2.要添加此播放器,我们必须创建 YoutubeEmbedFragment扩展Fragment 的新实例.

I tried to add in our androidx app the last Youtube Player for Publishers v2.1.2. To add this player we must create a new instance of YoutubeEmbedFragment extends Fragment.

这里的问题是该片段扩展了 android.app.Fragment ,在我们的应用程序中,我们使用了 androidx.appcompat.app.AppCompatActivity androidx.fragment.app ,所以当我想添加以下YouTube播放器片段时:

The problem here is that this Fragment extends android.app.Fragment and in our application we use androidx.appcompat.app.AppCompatActivity and androidx.fragment.app so when I want to add this Youtube player fragment like :

getChildFragmentManager()
    .beginTransaction()
    .replace(R.id.player_container, youTubeEmbedFragment)
    .commit();

由于以下原因而无法编译

It won't compile because of

第二个参数类型错误.成立:"com.google.android.youtube.player.YouTubeEmbedFragment",必填项:'androidx.fragment.app.Fragment'

Wrong 2nd argument type. Found: 'com.google.android.youtube.player.YouTubeEmbedFragment', required: 'androidx.fragment.app.Fragment'

我们如何保持使用支持片段但仍然使用库?

How can we stay using support fragment but also use the library ?

推荐答案

我们当前在应用中使用的是AndroidX,并且存在相同的问题:

We are currently using AndroidX in our app and we had the same problem:

Youtube Player for Publishers 2.1.2.未使用AndroidX,因此您必须使用完全合格的名称"访问类 android.app.FragmentTransaction 并使用需要 android.app.Fragment replace()方法,其中 youTubeEmbedFragment扩展:

The Youtube Player for Publishers v2.1.2. is not using AndroidX so you have tu use "Fully Qualified name" to access the class android.app.FragmentTransaction and use the replace() method that requires android.app.Fragment from which youTubeEmbedFragment extends :

这篇关于与YouTube发布商专用的片段类型不兼容的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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