我試圖把一個動作條有兩個圖標(一個要去的主要活動,而另一個會前一個)菜單欄有時會顯示圖標,有時不
的事情是,我有這樣的XML被用作菜單:
<item android:id="@+id/Main_App"
android:title="Main"
app:showAsAction="always|withText"
android:orderInCategory="1"
android:icon="@drawable/ic_home"/>
<item android:id="@+id/back_App"
android:title="Back"
app:showAsAction="always|withText"
android:orderInCategory="2"
android:icon="@drawable/ic_back"/>
而且使用它的代碼:
@覆蓋
public boolean onCreateOptionsMenu(Menu menu) {
getMenuInflater().inflate(R.menu.menu2, menu);
return true;
}
@Override
public boolean onOptionsItemSelected(MenuItem item) {
int id = item.getItemId();
if (id == R.id.Main_App) {
Intent getNewMessageAct = new Intent(this,UpLinksActivity.class);
startActivity(getNewMessageAct);
finish();
return true;
} else if (id == R.id.back_App){
Intent getNewMessageAct = new Intent(this,NewMessageActivity.class);
startActivity(getNewMessageAct);
finish();
return true;
}
return super.onOptionsItemSelected(item);
}
我總是用相同的菜單,有時圖標適合在動作條,有時不是。我不明白爲什麼會發生。
沒什麼做一下大小,因爲它具有安裝空間。
原因是什麼,可以理解的任何想法。
感謝您的回答,我一直在深入探索,發現問題所在。 我也把android:showAsAction,它很奇怪,因爲它給出了一個XML錯誤,但編譯它時,它運行良好。 – 2014-10-02 11:53:27