Is there any way to access menu_item_search menu item defined in fragment_photo_gallery layout using synthetic properties instead of using findItem method?
override fun onCreateOptionsMenu(menu: Menu, menuInflater: MenuInflater) {
super.onCreateOptionsMenu(menu, menuInflater)
menuInflater.inflate(R.menu.fragment_photo_gallery, menu)
//is there a way to access searchItem using synthetic properties?
val searchItem = menu.findItem(R.id.menu_item_search)
}
MenuInflater
serves a fundamentally different purpose than LayoutInflater
.
Despite both having "Inflater" part in its name and implementing methods that are named "inflate()", they do completely different things. MenuInflater
inflates Menu
s, where LayoutInflater
inflates View
s.
Kotlin Android Extensions were created to simplify usage of Android Views, not Android Menus, or anything that has inflate()
method.
Long story short - it is not possible to use KAE with Android Menus.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With