app:showAsAction 和android:showAsAction

app:showAsActionandroid

它有三個可選項
1.always:老是顯示在界面上
2.never:不顯示在界面上,只讓出如今右邊的三個點中
3.ifRoom:若是有位置才顯示,否則就出如今右邊的三個點中app

 

 

android:showAsActionspa

這個屬性可接受的值有:code

1.alaways:這個值會使菜單項一直顯示在ActionBar上。blog

2.ifRoom:若是有足夠的空間,這個值會使菜單顯示在ActionBar上。it

3.never:這個值菜單永遠不會出如今ActionBar是。io

4.withText:這個值使菜單和它的圖標,菜單文本一塊兒顯示。class

 

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
      .........  
}
相關文章
相關標籤/搜索