Reputation: 1
I'm struggling to get my options menu to appear and have tried nearly every solution available on stackoverflow. I have written my menu.xml file in a menu directory in res (shown below) and am attempting to place the code in a GameActivity.java file. When I test my program the menu does not appear, and when I click the missing menu area nothing happens.:
Here is the java code for my activity:
public class GameActivity extends AppCompatActivity {
int[] boardSize = {7, 5, 3, 1};
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_game);
}
@Override
public boolean onCreateOptionsMenu(Menu menu) {
MenuInflater inflater = getMenuInflater();
inflater.inflate(R.menu.menu, menu);
return true;
}
@Override
public boolean onOptionsItemSelected(MenuItem item) {
switch(item.getItemId()) {
//TODO
}
return true;
}
}
Here is my menu xml code:
<?xml version="1.0" encoding="utf-8"?>
<menu xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
xmlns:android="http://schemas.android.com/apk/res/android"
tools:context="io.github.ardenchew.lastpiece.MainActivity" >
<item
android:id="@+id/restart"
android:title="@string/restart"
app:showAsAction="always"
app:actionProviderClass="android.support.v7.app.MediaRouteActionProvider"
tools:icon="@drawable/mr_button_light" />
<item
android:id="@+id/resetScore"
android:title="@string/resetScore"
app:showAsAction="always"
app:actionProviderClass="android.support.v7.app.MediaRouteActionProvider"
tools:icon="@drawable/mr_button_light" />
<item
android:id="@+id/endGame"
android:title="@string/endGame"
app:showAsAction="always"
app:actionProviderClass="android.support.v7.app.MediaRouteActionProvider"
tools:icon="@drawable/mr_button_light" />
<item
android:id="@+id/killCpu"
android:title="@string/killCpu"
app:showAsAction="always"
app:actionProviderClass="android.support.v7.app.MediaRouteActionProvider"
tools:icon="@drawable/mr_button_light" />
</menu>
And here is my android manifest code:
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="io.github.ardenchew.lastpiece">
<application
android:allowBackup="true"
android:icon="@mipmap/ic_launcher"
android:label="@string/app_name"
android:roundIcon="@mipmap/ic_launcher_round"
android:supportsRtl="true"
android:theme="@style/AppTheme">
<activity
android:name=".MainActivity"
android:screenOrientation="portrait">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity
android:name=".PlayActivity"
android:screenOrientation="portrait" />
<activity
android:name=".InstructionsActivity"
android:screenOrientation="portrait" />
<activity
android:name=".GameActivity"
android:screenOrientation="portrait" />
</application>
</manifest>
Thanks so much
Upvotes: 0
Views: 170
Reputation: 526
Late but better no answer for others who has the same issue as I had
change these lines in your Theme or style file to
<style name="AppTheme.NoActionBar"> <item name="windowActionBar">true</item> <item name="windowNoTitle">false</item> </style>
Upvotes: 0
Reputation: 123
You should attach debugger and go deeper with this. The code inside an Activity looks good, maybe you should call super method inside onCreateOptionsMenu(Menu menu) method, or maybe the problem is in menu xml file, tools:context="io.github.ardenchew.lastpiece.MainActivity"
Upvotes: 0