Java 语法解释——getMenuInflater() [英] Java syntax explanation - getMenuInflater()

查看:46
本文介绍了Java 语法解释——getMenuInflater()的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

刚刚下载了 android studio,我正在使用 big nerd ranch 的 android 编程指南来学习绳索.

Just downloaded android studio, and I am using big nerd ranch's guide to android programming to learn the ropes.

当您启动 android studio 时,此代码已在主活动文件中:

When you start android studio this code is already in the main activity file:

 @Override
public boolean onCreateOptionsMenu(Menu menu) {
    // Inflate the menu; this adds items to the action bar if it is present.
    **getMenuInflater().inflate(R.menu.menu_quiz, menu);**
    return true;
}

我不明白 getMenuInflater 行.在我对 java 的短暂体验中,当使用句点将两者分开时,例如在 dog.bark() 中,只有一个对象出现在方法之前.这里看起来这行意味着调用在 getMenuInflater 方法中定义的 inflate 方法.但是,我查看了getMenuInflater()的源码,其body中并没有inflate方法.

I don't understand the getMenuInflater line. In my short experience with java only an object comes before a method when using a period to separate the two such as in dog.bark(). Here it looks like the line means call the inflate method which is defined within the getMenuInflater method. However, I checked the source code for getMenuInflater(), and there is no inflate method in its body.

有人可以为我揭开这一行中的语法的神秘面纱吗?

Can somebody demystify the syntax in this line for me?

推荐答案

getMenuInflater().inflate(R.menu.menu_quiz, menu); 是一个简短的形式:>

The line getMenuInflater().inflate(R.menu.menu_quiz, menu); is a short form of this:

MenuInflater inflater = getMenuInflater();
inflater.inflate(R.menu.menu_quiz, menu)

这篇关于Java 语法解释——getMenuInflater()的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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