【发布时间】:2025-12-15 23:10:01
【问题描述】:
我正在使用带有导航架构组件的 BottomSheetDialogFragment 类。我遵循单一活动模式,因此我只有一个活动和几个片段。下面是我的代码。
BottomSheetDialogFragment.kt
class LogoBottomSheetFragment : BottomSheetDialogFragment() {
private var _binding: FragmentBottomSheetAccountLogoBinding? = null
private val binding get() = _binding!!
override fun onCreateView(
inflater: LayoutInflater,
container: ViewGroup?,
savedInstanceState: Bundle?
): View? {
_binding = FragmentBottomSheetAccountLogoBinding.inflate(inflater, container, false)
return binding.root
}
override fun onDestroyView() {
super.onDestroyView()
_binding = null
}
}
这就是我如何从我的主要片段中打开我的 navigation.xml 中的对话框:
<dialog
android:id="@+id/logoBottomSheetFragment"
android:name="com.th3pl4gu3.locky.ui.main.add.account.LogoBottomSheetFragment"
android:label="LogoBottomSheetFragment"
tools:layout="@layout/fragment_bottom_sheet_account_logo" />
现在我想将底部工作表中的数据传递到主要片段。
有没有合适的方法来做到这一点?谁能帮帮我。
谢谢。
【问题讨论】:
-
你看过最近添加的Returning a result documentation吗?
-
这非常适合我的情况!非常感谢你做的这些。我不知道这种解决方法。
标签: android kotlin android-architecture-navigation android-bottomsheetdialog