Tag: article

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 toolbarrequireActivity().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