简体   繁体   English

来自外部按钮的导航抽屉活动更改片段

[英]Navigation Drawer Activity change fragment from external button

So I have set up the default Navigation Drawer Activity in Android Studio.所以我在 Android Studio 中设置了默认的 Navigation Drawer Activity。 I also added some buttons in the default navigation activity XML.我还在默认导航活动 XML 中添加了一些按钮。 The default navigation menu buttons obviously change the fragment, but I was wondering how I could also change the fragments via the buttons that I have added along the bottom?默认导航菜单按钮显然会更改片段,但我想知道如何通过底部添加的按钮更改片段? The reason I am having trouble is that the default nagivation menu buttons are part of a navGraph, whereas my buttons are not, thanks!我遇到问题的原因是默认导航菜单按钮是导航图的一部分,而我的按钮不是,谢谢!

[ [在此处输入图片说明 ][ ][在此处输入图片说明 ] ] 在此处输入图片说明

All you need to do is set onClickListeners on the button.您需要做的就是在按钮上设置onClickListeners

For example:例如:

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

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM