我尝试在我们的 androidx 应用程序中添加最后一个 Youtube Player for Publishers v2.1.2。要添加这个播放器,我们必须创建一个新的YoutubeEmbedFragment extends Fragment
.
这里的问题是这个片段扩展android.app.Fragment
并且在我们的应用程序中我们使用androidx.appcompat.app.AppCompatActivity
,androidx.fragment.app
所以当我想添加这个 Youtube 播放器片段时:
getChildFragmentManager()
.beginTransaction()
.replace(R.id.player_container, youTubeEmbedFragment)
.commit();
它不会编译,因为
第二个参数类型错误。找到:'com.google.android.youtube.player.YouTubeEmbedFragment',需要:'androidx.fragment.app.Fragment'
我们如何在使用支持片段的同时也使用库?