2016-03-09 39 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