java如何使用底部导航视图引用片段和活动?
我想为我的BaseActivity实现逻辑。java,我可以在活动和片段之间切换
我只想到只有片段的解决方案:https://www.truiton.com/2017/01/安卓-bottom-navigation-bar-example/或只有活动: How can I implement the bottom navigation bar into an app for 安卓? 如何在安卓应用程序中实现底部导航栏
但我不知道如何把它们结合起来
<安卓x.coordinatorlayout.widget.CoordinatorLayout
安卓:layout_width="match_parent"
安卓:layout_height="match_parent">
<com.google.安卓.material.bottomappbar.BottomAppBar
安卓:id="@+id/bottom_app_bar"
安卓:layout_width="match_parent"
安卓:layout_height="wrap_content"
app:fabAlignmentMode="center"
app:contentInsetRight="0dp"
app:contentInsetEnd="0dp"
app:contentInsetStart="0dp"
app:contentInsetLeft="0dp"
安卓:layout_gravity="bottom|center" >
<com.google.安卓.material.bottomnavigation.BottomNavigationView
安卓:id="@+id/bottomNavigation"
安卓:layout_width="match_parent"
安卓:layout_height="wrap_content"
安卓:layout_alignParentBottom="true"
安卓:foregroundGravity="bottom"
app:itemIconTint="@color/primary_icon_color"
app:itemRippleColor="@color/primary_icon_color_super_light"
app:itemTextColor="@color/primary_icon_color"
app:labelVisibilityMode="labeled"
app:menu="@menu/bottom_nav_menu" />
</com.google.安卓.material.bottomappbar.BottomAppBar>
# 1 楼答案
首先,您需要在res中创建一个菜单文件夹,并创建一个名为navigation的新文件。xml,您可以根据需要进行调整。下面是导航中的示例代码。我使用的xml:
因为您已经在BaseActivity布局中调用了底部导航,所以您只需要在BaseActivity的OnCreate块代码中添加一些代码。爪哇:
然后您可以在onCreate块代码下面添加此代码:
不要忘记在创建块代码时初始化变量abovr:
**编辑:**
如果您想转到另一个活动,只需在其中一个案例中添加一个意图
例如,我希望id为navigation_wishlist的底部导航在单击时移动到设置活动
我希望上述解决方案能解决你的问题