android - getMenuInflater().inflate(R.menu.main, menu);main无法解析或者不是字段,

标签 android

我想制作 map 。当我第一次尝试时,我遇到了问题。这是我的问题。

这是我的代码

@Override
public boolean onCreateOptionsMenu(Menu menu) {

    // Inflate the menu; this adds items to the action bar if it is present.
    getMenuInflater().inflate(R.menu.main, menu);
    return true;
}    

在这段代码中,我遇到了问题

getMenuInflater().inflate(R.menu.main, menu);

评论主要无法解析或不是字段

最佳答案

您的 res/menu 文件夹中应该有一个 menu.xml 文件(如果没有,请创建它),其内容如下:

<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:title="YOUR_MENU_ITEM"
        app:showAsAction="never"/>
</menu>

关于android - getMenuInflater().inflate(R.menu.main, menu);main无法解析或者不是字段,,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27199592/

相关文章:

java - android fragment 控制主要 Activity

Android:使用 getExternalStoragePublicDirectory(String type) 在外部存储上写入

java - 时间选择器对话框 : Change hours/minutes text size

java - 使用Chaquopy将python中的PyObject转换为android中的多个2d数组

java - Json Gson 期望 Begin Object,但实际上是字符串

android - android 中 epub 的 webview 不显示图像

android - 在 Android OrmLite 中使用多个数据库助手

android - android :gravity ="center" - Android时键盘隐藏的EditText

android - 将可绘制数组保存到文件 Android

android - 与我的数据库的单个列一起使用的查询出错