【问题标题】:Incompatible fragment type with the Youtube Player for Publishers与 Youtube Player for Publishers 不兼容的片段类型
【发布时间】:2020-04-13 18:37:42
【问题描述】:

我尝试在我们的 androidx 应用中添加最后一个 Youtube Player for Publishers v2.1.2。 要添加这个播放器,我们必须创建一个 YoutubeEmbedFragment extends Fragment 的新实例。

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

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

它不会编译因为

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

我们如何在使用支持片段的同时使用库?

【问题讨论】:

  • 分享链接,以防您错过谷歌搜索结果。试试这些解决方案stackoverflow.com/q/52577000/3497972
  • @akashzincle 是的,我看到了这篇文章,不幸的是它是一个不同的版本,并且实施已经改变。我有编辑帖子来分享版本。

标签: android android-fragments androidx youtubeplayer


【解决方案1】:

我们目前在我们的应用中使用 AndroidX,但遇到了同样的问题:

面向出版商的 Youtube 播放器 v2.1.2。未使用 AndroidX,因此您必须使用“完全限定名称”来访问 android.app.FragmentTransaction 类并使用需要 android.app.Fragmentreplace() 方法,youTubeEmbedFragment 从中扩展:

【讨论】:

    猜你喜欢
    • 2014-02-23
    • 1970-01-01
    • 1970-01-01
    • 2014-11-16
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多