我只想在我的主要活動中顯示我的菜單,然後從我的其他活動而不是菜單中獲得後退按鈕。現在我只是想知道如何從操作欄中刪除我不想要的活動的菜單。如何僅在主要活動中顯示菜單?
我的清單:我的主要活動中
<?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