我增加了共享操作使用下面的代碼ShareActionProvider顯示兩個圖標的系統圖標和共享圖標
<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="com.example.esir.jualeader.aspirant.MainActivity">
<item
android:id="@+id/action_settings"
android:orderInCategory="100"
android:title="@string/action_settings"
app:showAsAction="never" />
<item
android:id="@+id/action_finish"
android:orderInCategory="200"
android:title="Exit"
app:showAsAction="never" />
<item
android:id="@+id/share"
android:title="Share"
app:actionProviderClass="android.support.v7.widget.ShareActionProvider"
app:showAsAction="ifRoom"
/>
</menu>
和
private ShareActionProvider mShareActionProvider;
private void setShareIntent(Intent shareIntent){
if (mShareActionProvider != null) {
mShareActionProvider.setShareIntent(shareIntent);
}
}
private Intent createShareIntent(){
Intent actionsend=new Intent();
actionsend.setAction(Intent.ACTION_SEND);
actionsend.putExtra(Intent.EXTRA_TEXT,"Please Download Jua Leader App From : http://mstarsinnovations.com");
actionsend.setType("text/plain");
return Intent.createChooser(actionsend,"Share The Jua Leader Using");
}
@Override
public boolean onCreateOptionsMenu(Menu menu) {
getMenuInflater().inflate(R.menu.menu_main,menu);
// Locate MenuItem with ShareActionProvider
MenuItem item = menu.findItem(R.id.share);
// Fetch and store ShareActionProvider
mShareActionProvider = (ShareActionProvider) MenuItemCompat.getActionProvider(item);
setShareIntent(createShareIntent());
// Return true to display menu
return true;
}
爲什麼會出現其他圖標,它是唯一可點擊的圖標。如何刪除它? 任何幫助將得到高度評價。
你覺得'ShareActionProvider'看起來像什麼?如果你只是想分享按鈕,那麼你不需要'ShareActionProvider'。 – ianhanniballake
我需要什麼? –
你想讓它看起來像什麼? – ianhanniballake