gpt4 book ai didi

java - 应用程序在添加第二个navHostFragment时崩溃

转载 作者:行者123 更新时间:2023-12-02 13:40:36 25 4
gpt4 key购买 nike

由于某种条件,我需要在应用程序的两个不同 Activity 中使用两个navHostFragment
一切正常,直到我在应用程序中添加第二个navhostframent,这会创建一个带有错误的inflateexception:

Binary XML file line #36: Duplicate id 0x7f09018a, tag null, or parent id 0xffffffff with another fragment for androidx.navigation.fragment.NavHostFragment
以下是我的第二个navhost片段:
    <fragment
android:id="@+id/nav_host_fragment_supervisor"
android:name="androidx.navigation.fragment.NavHostFragment"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_above="@+id/bottomNav"
android:layout_below="@+id/appbar"
app:defaultNavHost="true"
app:navGraph="@navigation/navigation_graph_supervisor" />
请帮忙。

最佳答案

问题是您使用<片段>的方式。
您可以在XML中包含<片段>,以将片段实例嵌入布局中。
我可以建议为您的片段创建一个全新的布局,而不要使用<片段>。
编辑
创建一个单独的布局,然后将片段实例嵌入其中,例如:

<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/fragment_container"
android:layout_width="match_parent"
android:layout_height="match_parent" >

<fragment
android:id="@+id/nav_host_fragment_supervisor"
android:name="androidx.navigation.fragment.NavHostFragment"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_above="@+id/bottomNav"
android:layout_below="@+id/appbar"
app:defaultNavHost="true"
app:navGraph="@navigation/navigation_graph_supervisor" />

</FrameLayout>

关于java - 应用程序在添加第二个navHostFragment时崩溃,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/63829567/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com