2016-03-13 50 views

回答

0

在app/res/menu文件夾中創建新的菜單資源文件(xml文件)。在該文件中定義你想要的菜單。然後在活動.java文件中包含OnCreateOptionsMenu方法中的菜單。

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

好吧。當我製作新的菜單資源文件並對其進行更改時,我的主要活動的菜單資源文件也會發生更改。那就是問題所在。 –

+0

您可能正在使用重命名重構。檢查您的編輯器是否啓用了該功能。 –

+0

這是否解決了您的問題? –