Skip to content

Instantly share code, notes, and snippets.

@jaozinfs
Last active November 2, 2021 21:29
Show Gist options
  • Save jaozinfs/830aec4a4f0c32441e644d4956088530 to your computer and use it in GitHub Desktop.
Save jaozinfs/830aec4a4f0c32441e644d4956088530 to your computer and use it in GitHub Desktop.
class ExampleFragment : Fragment(R.layout.fragment_example) {
override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
val menuHost: MenuHost = requireActivity()
menuHost.addMenuProvider(object : MenuProvider {
override fun onCreateMenu(menu: Menu, menuInflater: MenuInflater) {
// Add o menu aqui
menuInflater.inflate(R.menu.example_menu, menu)
}
override fun onMenuItemSelected(menuItem: MenuItem): Boolean {
// Lidar com a seleção do menu
return true
}
}, viewLifecycleOwner, Lifecycle.State.RESUMED)
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment