Skip to content

Instantly share code, notes, and snippets.

@jaozinfs
Created November 2, 2021 21:24
Show Gist options
  • Save jaozinfs/924ce0b7ea2e7bfaeb34597fb369b4c2 to your computer and use it in GitHub Desktop.
Save jaozinfs/924ce0b7ea2e7bfaeb34597fb369b4c2 to your computer and use it in GitHub Desktop.
class ExampleActivity : ComponentActivity(R.layout.activity_example) {
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
// Add menu items without overriding methods in the Activity
addMenuProvider(object : MenuProvider {
override fun onCreateMenu(menu: Menu, menuInflater: MenuInflater) {
// Add menu items here
menuInflater.inflate(R.menu.example_menu, menu)
}
override fun onMenuItemSelected(menuItem: MenuItem): Boolean {
// Handle the menu selection
return true
}
})
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment