将两个 FragmentManager 类型导入同一个 class

Importing two FragmentManager types into the same class

在单个 activity 中,我试图组合 ViewPager 和 BottomNavigationView。我正在为 BottomNavigationView (AHBottomNavigation) 使用 third party library。现在,问题来了:

在尝试使用 FragmentManager 时,Viewpager 需要 android.support.v4.app.FragmentManager,但 BottomNavigationView 需要 android.app.FragmentManager。由于不能同时导入两个 类,我正处于下一步该做什么的十字路口。

PS: 一个快速解决这个问题的方法是找到一个更兼容的库。但是,就我而言,切换库非常昂贵,我该怎么办?

Since both classes cannot be imported at the same time, I am at crossroads as to what to do next.

您不需要同时导入它们 - 您可以使用每个 class 的完全限定名称。

android.support.v4.app.FragmentManager supportManager = getSupportFragmentManager();
android.app.FragmentManager oldAssManager = getFragmentManager();

P.S。 - 我强烈建议您放弃仍在使用旧片段管理器的第 3 方库,尤其是对于 BottomNavigationViewan official one already exists.

P.P.S - 根据 Material Design Guidelines(向下滚动到 "Transition"),你不应该做一个 "swipe" 动画来在选项卡之间切换,这就是a ViewPager 默认执行,因此您可能还需要重新考虑将这两个组件组合起来。

希望对您有所帮助!