Youtube 播放器支持片段不再适用于 Android studio 3.2 (androidx) [英] Youtube player support fragment no longer working on Android studio 3.2 (androidx)
问题描述
我刚刚将我的 Android Studio 更新到了 3.2 版,并按照说明使用了 androidx.
I just updated my Android Studio to version 3.2 and followed instructions to use androidx.
我一直在 Fragment 活动中使用 Youtube 片段,一切正常,但更新后,这 3 行简单的行现在给我错误无法解析方法'add(...)'":>
I've been using a Youtube fragment inside a Fragment activity and everything worked perfectly but, after the update, these 3 simple lines now give me the error "Cannot resolve method 'add(...)'":
YouTubePlayerSupportFragment youTubePlayerFragment = YouTubePlayerSupportFragment.newInstance();
FragmentTransaction transaction = getChildFragmentManager().beginTransaction();
transaction.add(R.id.youtube_fragment, youTubePlayerFragment).commit();
...当我尝试使用替换"而不是添加"时,它说:错误的第二个参数类型.找到:'com.google.android.youtube.player.YouTubePlayerSupportFragment',需要:'androidx.fragment.app.Fragment'"
...and when i try to use "replace" instead of "add" it says: "Wrong 2nd argument type. Found: 'com.google.android.youtube.player.YouTubePlayerSupportFragment', required: 'androidx.fragment.app.Fragment'"
...这让我认为问题与新的 AndroidX 功能有关.
...which makes me think that the problem has to do with the new AndroidX feature.
问题是add方法需要type的第二个参数:
The problem is that the add method wants the second parameter of type:
androidx.fragment.app.Fragment
...但 YouTubePlayerSupportFragment 返回一个:
...but the YouTubePlayerSupportFragment returns a:
android.support.v4.app.Fragment
有谁知道如何解决这个问题?有没有办法将android.support.v4.app.Fragment"转换成androidx.fragment.app.Fragment"?
Does anyone know how to solve this problem? Is there a way to cast the "android.support.v4.app.Fragment" into the "androidx.fragment.app.Fragment"?
推荐答案
我已经按照@Hosszful 的回答修复了它,我只使用这个文件就很容易了,https://gist.github.com/medyo/f226b967213c3b8ec6f6ab495一个>
I've fixed it by following the @Hosszful answer, I made it easy by just using this file, https://gist.github.com/medyo/f226b967213c3b8ec6f6bebb5338a492
这篇关于Youtube 播放器支持片段不再适用于 Android studio 3.2 (androidx)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!