我正在使用MainActivity來擴展Activity類。項目使用的最小API爲11.當我充氣菜單項時,它總是顯示爲溢出。即使使用app:showAsAction,Android菜單項也會顯示在溢出區域中
public class MainActivity extends Activity {
....
@Override
public boolean onCreateOptionsMenu(Menu menu)
{
// Inflate the Menu Items
getMenuInflater().inflate(R.menu.menu_main,menu);
return true;
}
<?xml version="1.0" encoding="utf-8"?>
<menu xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
tools:context=".MainActivity">
<item android:id="@+id/attach"
android:title="Attachment"
android:orderInCategory="1"
app:showAsAction="always"/>
</menu>
Styles.xml
<!-- Base application theme. -->
<style name="AppTheme" parent="android:Theme.Holo.Light">
<!-- Customize your theme here. -->
<item name="colorPrimary">@color/colorPrimary</item>
<item name="colorPrimaryDark">@color/colorPrimaryDark</item>
<item name="colorAccent">@color/colorAccent</item>
</style>
請不要把代碼 – Raghavendra
後的截圖menu_main.xml文件 –