Site icon JoinAppStudio

MenuProvider API— Android. In this article, we will learn how to… | by Nav Singh | Aug, 2023

MenuProvider API— Android. In this article, we will learn how to… | by Nav Singh | Aug, 2023

override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
super.onViewCreated(view, savedInstanceState)
// Add options menu to the toolbar
requireActivity().addMenuProvider(object : MenuProvider {
override fun onCreateMenu(menu: Menu, menuInflater: MenuInflater) {
menuInflater.inflate(R.menu.main_menu, menu)
}
override fun onMenuItemSelected(menuItem: MenuItem): Boolean {
return when (menuItem.itemId) {
R.id.settings -> {
true
}
else -> false
}
}
}, viewLifecycleOwner)
}

Source link

Exit mobile version