【发布时间】:2014-02-14 16:48:09
【问题描述】:
在测试应用程序并按下我的 Android 2.2 手机上的菜单按钮时,它给了我一个设置栏,点击后,我无处可去。但是,当我在我的 main.class 文件中看到设置它的代码时,找不到它。
在我的字符串文件中,它是由自己创建的,并称自己为“action_settings”。我尝试删除该行,但它使应用程序无法编译。我在这里做什么?
@Override
public boolean onCreateOptionsMenu(Menu menu) {
// three lines below are default
// Inflate the menu; this adds items to the action bar if it is present.
// getMenuInflater().inflate(R.menu.main, menu);
// return true;
// Make MenuInflater
MenuInflater inflater = getMenuInflater();
inflater.inflate(R.menu.main, menu);
SharedPreferences settings = getSharedPreferences("prefs", 0);
//MENU//
menu.add(1, 1, Menu.FIRST, "Settings MENU?");
menu.add(1, 2, Menu.FIRST +1, "Clear");
menu.add(1, 3, Menu.FIRST +2, "Feedback");
menu.add(1, 4, Menu.FIRST +3, "About");
// Return True
return true;
}
【问题讨论】:
-
你能发布你正在膨胀的 res/menu/main.xml 吗?
-
我知道这里有什么问题。我复制/粘贴了我不理解的代码。 Menu/main 中有一个名为 action_settings 的项目...
-
我只是不知道充气机是什么,也不知道它的用途。
-
A
MenuInflater从 XML 扩展菜单,将每个元素添加到传递给inflate的Menu中。这样您就无需手动添加项目(就像您在此处所做的那样)。
标签: android android-actionbar settings