Igo*_*jda 3 kotlin kotlin-android-extensions
有没有办法使用合成属性而不是使用findItem方法访问fragment_photo_gallery布局中定义的menu_item_search菜单项?
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)
}
Run Code Online (Sandbox Code Playgroud)
小智 9
MenuInflater
服务于一个根本不同的目的LayoutInflater
.
尽管名称中包含"Inflater"部分并且实现名为"inflate()"的方法,但它们完全不同.MenuInflater
膨胀Menu
s,LayoutInflater
膨胀View
s.
Kotlin Android Extensions的创建是为了简化Android视图的使用,而不是Android Menus或任何有inflate()
方法的东西.
长话短说 - 不可能将KAE与Android菜单一起使用.
归档时间: |
|
查看次数: |
2677 次 |
最近记录: |