2016-03-09 52 views
0

我试图在android studio中设置一个共享按钮。当我点击操作栏上的分享按钮时,没有任何反应。下面是它看起来像在 menu_main XML:错误尝试在Android操作栏中使用Action.Send

<item 
    android:id="@+id/action_share" 
    android:icon="@drawable/sharebutton" 
    android:title="@string/abc_shareactionprovider_share_with" 
    app:showAsAction="ifRoom"/> 

这里是MainActivity java代码:

public boolean onOptionsItemSelected(MenuItem item) { 
    // Handle action bar item clicks here. The action bar will 
    // automatically handle clicks on the Home/Up button, so long 
    // as you specify a parent activity in AndroidManifest.xml. 
    int id = item.getItemId(); 

    //noinspection SimplifiableIfStatement 
    if (id == R.id.action_settings) { 
     return true; 
    } 
    if (id == R.id.action_share) { 
     Intent sendIntent = new Intent(); 
     sendIntent.setAction(Intent.ACTION_SEND); 
     sendIntent.putExtra(Intent.EXTRA_TEXT, "Download this App!. "); 
     sendIntent.setType("text/plain"); 
     return true; 
    } 


    return super.onOptionsItemSelected(item); 
} 

的应用程序本身,当我点击操作栏上的按钮没有任何反应。

回答

0

您已省略startActivity(sendIntent);

if (id == R.id.action_share) { 
    Intent sendIntent = new Intent(); 
    sendIntent.setAction(Intent.ACTION_SEND); 
    sendIntent.putExtra(Intent.EXTRA_TEXT, "Download this App!. "); 
    sendIntent.setType("text/plain"); 
    startActivity(sendIntent); 
    return true; 
} 
+0

感谢它完美的工作! –

+0

不客气 – Inducesmile