我只想在我的主要活动中显示我的菜单,然后从我的其他活动而不是菜单中获得后退按钮。现在我只是想知道如何从操作栏中删除我不想要的活动的菜单。如何仅在主要活动中显示菜单?
我的清单:我的主要活动中
<?xml version="1.0" encoding="utf-8"?>
<application
android:allowBackup="true"
android:icon="@mipmap/ic_launcher"
android:label="@string/app_name"
android:theme="@style/AppTheme" >
<activity
android:name=".Insulter"
android:label="@string/app_name" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity
android:name="Favourites"
android:launchMode = "singleInstance">
</activity>
<activity
android:name="Settings"
android:launchMode = "singleInstance">
</activity>
</application>
我的菜单揭幕战:
@Override
public boolean onOptionsItemSelected(MenuItem item) {
// Handle action bar item clicks here. The action bar will
// automatically handle clicks on the Home/Up button, so long
// as you specify a parent activity in AndroidManifest.xml.
int id = item.getItemId();
//noinspection SimplifiableIfStatement
if (id == R.id.action_settings) {
Intent startSettings = (new Intent(Insulter.this,Settings.class));
startActivity(startSettings);
return true;
} else if (id == R.id.exit_the_app) {
finish();
return true;
} else if (id == R.id.favourites) {
Intent startFavs = (new Intent(Insulter.this, Favourites.class));
String[] objects = new String[favs.size()];
favs.toArray(objects);
final ArrayList<String> list = new ArrayList<>(Arrays.asList(objects));
startFavs.putStringArrayListExtra("favs",list);
startActivity(startFavs);
return true;
}
return super.onOptionsItemSelected(item);
}
简单的'不要附加菜单'的其他活动..! – AndiGeeky
@AndiGeeky我很抱歉,我会把这个放在哪里?在清单中? – James
只需从您的活动'onCreateOptionsMenu'中移除此方法.. !! – AndiGeeky