YouTube播放器支持片段不再适用于Android Studio 3.2(androidx) [英] Youtube player support fragment no longer working on Android studio 3.2 (androidx)

查看:85
本文介绍了YouTube播放器支持片段不再适用于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方法想要第二个参数类型:

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/f226b967213c3b8ec6f6bebb5338a492

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屋!

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