4Manuals

  • PDF Cloud HOME

如何在导航图中将包含的图设置为startDestination? Download

    如何在Android中使用WebRTC缩放相机 Android 10,API29:在应用程序文件夹中使用C ++库编写文件会使应用程序崩溃 如何将动态值传递给渐变xml 加载数据并推送到未显示的RecyclerView中 调用Model类的函数时出现java.lang.NullPointerException 从网络加载图像时,“接收到完整的报头之前关闭连接 Ionic 3错误:“缺少文件google-services.json。没有它,Google Services插件将无法运行。”在离子科尔多瓦建立/准备Android androidx.appcompat.view.menu.MenuItemImpl无法转换为android.widget.TextView 从Firebase发送推送通知不起作用 类型“文件”的表达式“目标”不能作为函数调用

我的应用程序中有多个模块,其中一些是UI模块。UI模块中有一个NavigationGraph,它包含在应用程序内部。

该应用同时具有BottomNavigationView和Toolbar。因此,我陷入了一些过渡。我将在下面分享代码并阐述问题。

这是我的应用导航图

<navigation xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    xmlns:tools="http://schemas.android.com/tools"
    android:id="@+id/mobile_navigation"
    app:startDestination="@+id/navigation_group">

    <fragment
        android:id="@+id/navigation_group"
        android:name="com.example.group.view.fragments.GroupHostFragment"
        android:label="@string/title_group"
        tools:layout="@layout/fragment_home" />

    <fragment
        android:id="@+id/navigation_scene"
        android:name="com.wisilica.scene.view.SceneHostFragment"
        android:label="@string/title_scene"
        tools:layout="@layout/fragment_dashboard" />

    ...

</navigation>

每个片段都是UI模块中的主机片段。

我的仪表板活动布局


<?xml version="1.0" encoding="utf-8"?>
<androidx.constraintlayout.widget.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    android:id="@+id/container"
    android:layout_width="match_parent"
    android:layout_height="match_parent">

    <com.google.android.material.appbar.AppBarLayout
        android:id="@+id/appbarLayout">

        <com.google.android.material.appbar.MaterialToolbar
            android:id="@+id/toolbar" />
    </com.google.android.material.appbar.AppBarLayout>

    <com.google.android.material.bottomnavigation.BottomNavigationView
        android:id="@+id/bottomNavView"

        .................

        app:menu="@menu/bottom_nav_menu" />

    <fragment
        android:id="@+id/nav_host_fragment"
        android:name="androidx.navigation.fragment.NavHostFragment"

        .................

        app:navGraph="@navigation/mobile_navigation" />

</androidx.constraintlayout.widget.ConstraintLayout>

DashboardActivity代码

        setupActionBarWithNavController(navController, appBarConfiguration)

        toolbar.setupWithNavController(navController)
        bottomNavView.setupWithNavController(navController)

点击底部菜单项时,它运行良好,并导航到其他主机片段。但是问题是 homeUp按钮仅显示单击第二个主机片段,而不是单击第一个主机片段及其目的地。

   Dashboard Graph
    |            |
    v            v
hostA     |   host B
  |              |
  V              V
dest1 (dest2)    dest1(dest2)

最初,我们在hostA上(将显示目标1),但是homeUp符号将不显示(确定),然后单击dest2,homeUp符号将不显示(为什么)

单击了底视图菜单项并移至hostB,显示了homeUp符号(为什么),并单击了按钮
并移至hostA。

我尝试将hostA和hostB的navGraph包括在内,然后它对BottomNavigationView没有响应

请帮助我解决此问题?

预先感谢

1 个答案:

答案 0 :(得分:0)

您需要对Graph XML Fragments使用相同的菜单项ID。

其他事物将被自动管理。



Similar searches
    有没有办法使用JavaScript按名称(不是ID)搜索Trello卡? 使用数据管道将EFS备份到S3 在方括号中使用替代项时,Python正则表达式子项无法正常工作 使用Mailkit发送CSHTML View邮件 根据输入数据集使用SAS生成SQL代码