Android应用分享按钮未显示

时间:2014-09-18 15:55:59

标签: java android android-layout android-intent

我创建了一个新的应用程序,我想在顶部栏的右侧显示SHARE按钮。它曾用于以前的应用程序,但在最后一个应用程序中没有显示共享图标,我不知道原因:

RES /菜单/ main.xml中

<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" >

    <item
        android:id="@+id/action_settings"
        android:orderInCategory="100"
        android:title="@string/action_settings"
        app:showAsAction="never"/>

    <item
        android:id="@+id/share"
        android:showAsAction="always"
        android:title="@string/action_share"
        android:icon="@android:drawable/ic_menu_share"
        />

</menu>

MainActivity.java

@Override
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);
    return true;
}

@Override
public boolean onOptionsItemSelected(MenuItem item) {
    switch(item.getItemId()){
    case R.id.share:
        Intent shareIntent = new Intent(Intent.ACTION_SEND);
        shareIntent.setType("text/plain");
        shareIntent.putExtra(Intent.EXTRA_SUBJECT, "subject");
        shareIntent.putExtra(Intent.EXTRA_TEXT, "text");
        startActivity(Intent.createChooser(shareIntent, "Share Via"));
        break;
    default:
        break;

    }
    return true;
}

我不知道这是否重要,但我在清单上有这个目标:

<uses-sdk
        android:minSdkVersion="9"
        android:targetSdkVersion="21" />

任何帮助都非常感谢。

0 个答案:

没有答案
相关问题