You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

Android Navigation 2.5.2底部导航栏二次点击才响应问题求助

环境与基础配置

  • 使用Navigation 2.5.2版本
  • 主菜单采用BottomNavigationView,包含三个选项:A(首页)、B、C
  • 页面跳转逻辑:
    • A → Aa → Ab → D
    • B → D
    • C → Ca → D

需求

  1. 点击底部菜单时清空对应导航栈(例:从A进入Aa后点击B,再返回A时显示A而非Aa)
  2. 系统返回键需逐层出栈(例:A→Aa→Ab,按返回键依次回到Aa、A)

当前问题

路径为B→D,按返回键回到B,再按返回键回到首页A后,再次点击底部菜单B,第一次点击无响应,第二次点击才显示B页面,无报错信息。未通过返回键操作时,底部菜单点击正常。

相关代码

mobile_navigation.xml

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

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

    <fragment
        android:id="@+id/navigation_dashboard"
        android:name="com.example.www.ui.dashboard.DashboardFragment"
        android:label="@string/title_dashboard"
        tools:layout="@layout/fragment_dashboard">
        <action
            android:id="@+id/action_dashboard"
            app:destination="@+id/navigation_seconddash"
            app:popUpTo="@id/navigation_dashboard"
            app:popUpToSaveState="true" />
    </fragment>

    <fragment
        android:id="@+id/navigation_seconddash"
        android:name="com.example.www.ui.home.SecondDashboardFragment"
        android:label="DashBoard2"
        tools:layout="@layout/fragment_seconddashboard"/>

    <fragment
        android:id="@+id/navigation_notifications"
        android:name="com.example.www.ui.notifications.NotificationsFragment"
        android:label="@string/title_notifications"
        tools:layout="@layout/fragment_notifications" />
</navigation>

Dashboard点击事件代码

binding.btn.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                Navigation.findNavController(view).navigate(R.id.action_dashboard);
            }
        });

已尝试方案

  • 使用deeplink(未实现清空栈的需求)
  • 更换Navigation版本
    均未解决问题。

内容的提问来源于stack exchange,提问作者user20363150

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.08.14 21:25:24