Android开发-getMenuInflater(R.menu.main,menu) [英] Android Development - getMenuInflater(R.menu.main, menu)

查看:100
本文介绍了Android开发-getMenuInflater(R.menu.main,menu)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在学习android并遵循一个简单的相机应用程序教程.我已经复制了一段代码,但是我遇到了一个错误,我不确定为什么.

I'm learning android and following a simple camera app tutorial. There's a snippet of code that I've reproduced but I am getting an error on it and I'm not sure why.

我正在使用的教程是

http://iwearshorts.com/blog/android-development-102/

代码段是:

@Override
public boolean onCreateOptionsMenu(Menu menu){
    getMenuInflater().inflate(R.menu.main, menu);
    return true;
}

在我的项目中,R.menu.main出现错误.更具体地说,"R.menu.main"中的单词菜单无法解析或不是字段.

In my project, I am getting an error with R.menu.main. More specifically, the word menu in 'R.menu.main' cannot be resolved or is not a field.

我在教程中看不到任何会导致此问题的内容.我唯一能想到的是,这与使用其他版本的Android有关.我不确定该如何检查.

I don't see anything in the tutorial that I've missed that would cause this. The only thing I can think of is that it's related to using a different version of Android. I'm not sure how I would check this though.

感谢您的任何建议,谢谢.

I appreciate any advice, thank you.

推荐答案

/res/menu/文件夹中添加 menu.xml 文件,这是一个示例:

add the menu.xml file inside /res/menu/ folder, this is an example:

<menu xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto">

    <item
        android:id="@+id/action_settings"
        android:orderInCategory="100"
        android:title="my menu Item!"
        app:showAsAction="never"/>

</menu>

这篇关于Android开发-getMenuInflater(R.menu.main,menu)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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