简体   繁体   English

为什么onCreateOptionsMenu(Menu menu)返回一个布尔值?

[英]Why does onCreateOptionsMenu(Menu menu) return a boolean?

I'm confused as to why it returns a boolean here when within the last line of code. 我很困惑为什么在代码的最后一行中它会在此处返回布尔值。 What's the use of this and why does it matter? 这有什么用,为什么重要?

@Override
public boolean onCreateOptionsMenu(Menu menu) {
    return super.onCreateOptionsMenu(menu);
}

From documentation for this method: 从有关此方法的文档中:

Returns boolean You must return true for the menu to be displayed; 返回布尔值要显示菜单,必须返回true;否则,返回false。 if you return false it will not be shown. 如果返回false,则不会显示。

To my understanding, this is to confirm that menu was created correctly, it is populated only with valid elements, so it can safely be used. 据我了解,这是为了确认菜单创建正确,仅在菜单中填充了有效元素,因此可以安全地使用菜单。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 onCreateOptionsMenu是否将菜单传递给onOptionsItemSelected? - Does onCreateOptionsMenu pass a menu to onOptionsItemSelected? 了解为什么 onCreateOptionsMenu 不显示菜单 - Understanding why onCreateOptionsMenu is not displaying a menu 什么是 onCreateOptionsMenu(菜单菜单) - What is onCreateOptionsMenu(Menu menu) 为什么Android onCreateOptionsMenu方法返回super.onCreateOptionsMenu? - Why does the Android onCreateOptionsMenu method return super.onCreateOptionsMenu? 显示菜单但未调用 onCreateOptionsMenu() - Menu showing but onCreateOptionsMenu() not called 我收到此错误“ RecyclerView:未连接适配器; 跳过布局”,但我正在使用“布尔值onCreateOptionsMenu(菜单菜单)” - I'm getting this error “RecyclerView: No adapter attached; skipping layout” but i'm working with “ boolean onCreateOptionsMenu(Menu menu)” 如何在onCreateOptionsMenu中动态更改菜单 - How to dynamically change menu in onCreateOptionsMenu 在onCreateOptionsMenu中创建菜单的menuInflater无法正常工作 - menuInflater to create a menu in the onCreateOptionsMenu not working 如何延迟 onCreateOptionsMenu(Menu menu)? - How do I delay onCreateOptionsMenu(Menu menu)? onCreateOptionsMenu(菜单菜单)和onPrepareOptionsMenu(菜单菜单)有什么区别? - What is the difference between onCreateOptionsMenu(Menu menu) and onPrepareOptionsMenu(Menu menu)?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM