底部导航抽屉
Bottom Navigation Drawer
我在实施底部抽屉时遇到问题,如以下示例所示:
https://material.io/design/components/navigation-drawer.html#bottom-drawer
我首先做了类似的事情:
https://material.io/develop/android/components/navigation-view/
但我不知道应该如何将它锚定到底部。我曾尝试使用 layout_gravity 的不同组合,但它要么在开始时崩溃,要么在尝试使用以下方式打开它时崩溃:
drawer_layout.openDrawer(Gravity.START)
我有点卡住了所以任何帮助将不胜感激!
感谢@Mike.M,我找到了解决方案。我已经使用 BottomSheetDialogFragment 从菜单中显示:
这只是一个示例 kotlin class
class BottomDialogFragment : BottomSheetDialogFragment() {
override fun onCreateView(inflater: LayoutInflater, container: ViewGroup?, savedInstanceState: Bundle?): View? {
return inflater.inflate(R.layout.f_bottomsheet, container, false)
}
companion object {
fun newInstance(): MainBottomDialogFragment {
return MainBottomDialogFragment()
}
}
}
我可以在 xml 文件中设置我认为合适的样式 - 另一个优点是它简单且非常灵活。
我在实施底部抽屉时遇到问题,如以下示例所示:
https://material.io/design/components/navigation-drawer.html#bottom-drawer
我首先做了类似的事情:
https://material.io/develop/android/components/navigation-view/
但我不知道应该如何将它锚定到底部。我曾尝试使用 layout_gravity 的不同组合,但它要么在开始时崩溃,要么在尝试使用以下方式打开它时崩溃:
drawer_layout.openDrawer(Gravity.START)
我有点卡住了所以任何帮助将不胜感激!
感谢@Mike.M,我找到了解决方案。我已经使用 BottomSheetDialogFragment 从菜单中显示:
这只是一个示例 kotlin class
class BottomDialogFragment : BottomSheetDialogFragment() {
override fun onCreateView(inflater: LayoutInflater, container: ViewGroup?, savedInstanceState: Bundle?): View? {
return inflater.inflate(R.layout.f_bottomsheet, container, false)
}
companion object {
fun newInstance(): MainBottomDialogFragment {
return MainBottomDialogFragment()
}
}
}
我可以在 xml 文件中设置我认为合适的样式 - 另一个优点是它简单且非常灵活。