app:showAsAction
它有三個可選項
1.always:總是顯示在界面上
2.never:不顯示在界面上,只讓出現在右邊的三個點中
3.ifRoom:如果有位置才顯示,不然就出現在右邊的三個點中
android:showAsAction
這個屬性可接受的值有:
1.alaways:這個值會使菜單項一直顯示在ActionBar上。
2.ifRoom:如果有足夠的空間,這個值會使菜單顯示在ActionBar上。
3.never:這個值菜單永遠不會出現在ActionBar是。
4.withText:這個值使菜單和它的圖標,菜單文本一起顯示。
When using the appcompat library, menu resources should refer to the showAsAction in the app: namespace, not the android: namespace. Similarly, when not using the appcompat library, you should be using the android:showAsAction attribute.
I think the problem is that you are mixing Framework Activity and AppCompat menu. You should use AppCompatActivity with AppCompat Action bar and app:showAsAction; or Activity with android:showAsAction.
public class MainActivity extends AppCompatActivity {//像這樣的AppCompatActivity 需要使用app:showAsAction .......... }
public class MainActivity extends Activity{ //像這樣的Activity 需要使用android:showAsAction ......... }