getMenuInflater出错

时间:2015-04-16 15:39:16

标签: android

MainActivity

public boolean onCreateOptionsMenu(Menu menu) {
    // Inflate the menu; this adds items to the action bar if it is present.

    getMenuInflater().inflate(R.menu.main, menu);
    MenuItem item = menu.findItem(R.id.menu_item_share);

    // Fetch and store ShareActionProvider
    ShareActionProvider mShare = (ShareActionProvider) item.getActionProvider();

    Intent shareIntent = new Intent(Intent.ACTION_SEND);
    shareIntent.setAction(Intent.ACTION_SEND);
    shareIntent.setType("text.plain");
    shareIntent.putExtra(Intent.EXTRA_TEXT,"Try this e-Learning app!");

    mShare.setShareIntent(shareIntent);

    menu.add(0, 1, 1, "Home");
    menu.add(0, 2, 2, "About");
    menu.add(0, 3, 3, "Help");
    menu.add(0, 4, 4, "Settings");
    menu.add(0, 5, 5, "Exit");

    return true;
}

添加getMenuInflater()。inflate(R.menu.main,menu)后,

我的应用程序的选项菜单突然出现一个额外的"设置"哪个不起作用。我尝试删除getMenuInflater()和这些相关的代码,然后是"设置" disappered。有什么解决方案吗?请帮忙!

http://i.stack.imgur.com/rPaPZ.png

main.xml中

<item
    android:id="@+id/action_settings"
    android:orderInCategory="100"
    android:showAsAction="never"
    android:title="@string/action_settings"/>
<item
    android:id="@+id/action_home"
    android:icon="@drawable/ic_action_view_as_grid"
    android:maxHeight="32dip"
    android:maxWidth="32dip"
    android:showAsAction="always"
    android:title="@string/action_home"/>


<item
    android:id="@+id/menu_item_share"
    android:actionProviderClass="android.widget.ShareActionProvider"
    android:showAsAction="always"
    android:title="Share"/>

0 个答案:

没有答案