Android的Navigation组件能否用于在BottomSheet内导航(即在单个底部页替换/添加片段)?
我知道如何使用导航图中的
我知道如何使用导航图中的
NavHostFragment
是一个容器,它的内容会被替换。所以,如果您想在 BottomSheetDialogFragment
中拥有一个与外部 NavHostFragment
的容器(即整个活动的整体内容)不同的容器,您需要在您的 BottomSheetDialogFragment
布局中添加一个单独的 NavHostFragment
,并且该容器具有自己的导航图。navigate()
操作,则可以使用 requireParentFragment().findNavController()
访问外部 NavController
)。Caused by: java.lang.IllegalArgumentException: Binary XML file line #8: Duplicate id 0x7f080095, tag null, or parent id 0xffffffff with another fragment for androidx.navigation.fragment.NavHostFragment at androidx.fragment.app.FragmentLayoutInflaterFactory.onCreateView(FragmentLayoutInflaterFactory.java:116)
的错误提示。 - VINbtn_bottom_sheet.setOnClickListener { FragmentOne().show(supportFragmentManager, "appBottomSheet") }
- VINshow()
来显示你的 BottomSheetDialogFragment,而不是使用 <dialog>
目标来显示你的对话框,这有什么原因吗?确保你没有在多个地方使用相同的 android:id
(你的外部 NavHostFragment
不应该与内部的相同)。 - ianhanniballakeshow()
的原因是我正在尝试使用导航组件,从底部表单作为导航宿主开始,而无需将活动作为起始导航宿主。你知道这是否可能吗? - VIN
如果不是通过导航控制器返回,就关闭对话框并返回true。 dialog.dismiss() true } 返回true }
- uberchilly