【问题标题】:Navigation Drawer Activity change fragment from external buttonNavigation Drawer Activity 从外部按钮更改片段
【发布时间】:2020-03-18 19:08:58
【问题描述】:

所以我在 Android Studio 中设置了默认的 Navigation Drawer Activity。我还在默认导航活动 XML 中添加了一些按钮。默认导航菜单按钮显然会更改片段,但我想知道如何通过底部添加的按钮更改片段?我遇到问题的原因是默认导航菜单按钮是 navGraph 的一部分,而我的按钮不是,谢谢!

[][]

【问题讨论】:

  • 你想做什么?
  • 允许我放置在底部的按钮更改片段,就像侧面导航面板上的菜单按钮一样

标签: java android android-studio android-fragments android-activity


【解决方案1】:

您只需在按钮上设置onClickListeners

例如:

val postButton = findViewById<Button>(R.id.post_button)

postButton.setOnClickListener {
    findNavController().navigate(R.id.post_fragment)
}

【讨论】:

    猜你喜欢
    • 2014-08-27
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2015-09-06
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多