什么是onCreateOptionsMenu(菜单菜单) [英] What is onCreateOptionsMenu(Menu menu)

查看:120
本文介绍了什么是onCreateOptionsMenu(菜单菜单)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

方法onCreateOptionsMenu(Menu menu)中的两个参数Menu和menu是什么,以及如何使用此方法. 我还有一个问题,为什么在

What are the two parameters Menu and menu in method onCreateOptionsMenu(Menu menu) and how to use this method. I have another question why this parameter is used in

Intent intent = new Intent(this, DisplayMessageActivity.class);

推荐答案

Menu只是参数菜单的类型.例如,对于名为string,dog等的变量,您可以使用String类型.在这种情况下,对于名为menu的参数,则具有Menu类型.

Menu is just the type of the parameter menu. For example you can have a String type for a variable named string, dog, etc. And in this case there's a Menu type for a parameter named menu.

您可以使用onCreateOptionsMenu()来指定活动的选项菜单. 通过这种方法,您可以将菜单资源(以XML定义)添加到回调中提供的Menu中.

You use onCreateOptionsMenu() to specify the options menu for an activity. In this method, you can inflate your menu resource (defined in XML) into the Menu provided in the callback.

例如:

@Override
public boolean onCreateOptionsMenu(Menu menu) {
    MenuInflater inflater = getMenuInflater();
    inflater.inflate(R.menu.game_menu, menu);
    return true;
}

有关更多信息,请访问此链接.

Fore more information, visit this link.

关于

在实例方法或构造函数中,这是对当前对象的引用-当前对象正在调用其方法或构造函数.

Within an instance method or a constructor, this is a reference to the current object — the object whose method or constructor is being called.

例如:

public void sendMessage() {
    Intent intent = new Intent(this, DisplayMessageActivity.class);
}

构造函数将两个参数和一个Context作为其第一个参数. 代表环境数据,并提供有关应用程序环境的全局信息.

The constructor takes two parameters and a Context as its first parameter. this represents environment data and provides global information about an application environment.

有关您提供的意图示例的更多信息,请检查退出.

For more information on the intent example you provided, check this out.

这篇关于什么是onCreateOptionsMenu(菜单菜单)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆