首页 > 解决方案 > 当我们转到其他图形时如何在抽屉中显示汉堡包(具有多模块的导航组件)

问题描述

我用多模块制作应用程序:-app-SMS

现在我在模块应用程序中绘制图表:

<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/nav_home">

    <include app:graph="@navigation/sms_navigation" />

    <fragment
        android:id="@+id/nav_home"
        android:name="com.example.messages.ui.home.HomeFragment"
        android:label="@string/menu_home"
        tools:layout="@layout/fragment_home" />

    <fragment
        android:id="@+id/nav_sms"
        android:name="com.example.messages.ui.sms.SmsFragment"
        android:label="@string/menu_sms"
        tools:layout="@layout/fragment_sms">
        <action
            android:id="@+id/action_sms_not_met"
            app:destination="@id/sms_navigation"/>
    </fragment>

    <fragment
        android:id="@+id/nav_preferences"
        ... />

    <fragment ... />
</navigation>

并在模块 SMS

<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/sms_navigation"
    app:startDestination="@id/nav_sms_welcome_fragment">

    <fragment
        android:id="@+id/nav_sms_welcome_fragment"
        android:name="com.example.sms.ui.welcome.WelcomeFragment"
        android:label="@string/welcome"
        tools:layout="@layout/list_sms_fragment">
        <action
            android:id="@+id/openListSms"
            app:destination="@+id/nav_sms_list_fragment"
            />
    </fragment>

    <fragment
        android:id="@+id/nav_sms_list_fragment"
        android:name="com.example.sms.ui.listsms.ListSmsFragment"
        android:label="@string/list_sms"
        tools:layout="@layout/list_sms_fragment" />
</navigation>

当我运行应用程序时,我看到了主页片段和抽屉的汉堡包。接下来我打开抽屉并单击“短信”行。如果变量“enableSMS”为假,则显示欢迎片段,否则打开“​​短信列表片段”。

问题 1:当我在那里(短信列表片段)时,我看到按钮向上。我想看到汉堡包而不是按钮向上。打开设置或主页片段时就可以了。我该如何解决?

问题2 该案例可能与第一个问题有关当我打开短信列表片段并按后退按钮时,我将返回片段欢迎一段时间并再次向我显示短信列表片段。我无法返回首页片段,因为我有循环。在片段(短信和欢迎)中,我有代码:

// SmsFragment
if (enableSMS) findNavController().navigate(R.id.action_sms_not_met)

// WelcomeFragment
if (enableSMS) findNavController().navigate(com.example.sms.R.id.openListSms)

如果我从主页片段开始,然后转到 sms 列表片段,我按下后退按钮我想查看主页片段,因为它是打开 sms 片段之前的第一个片段。

任何想法?

感谢帮助 :)

标签: androidandroid-fragmentsnavigation-drawermulti-module

解决方案


推荐阅读