1
我想在標題欄上獲得一個工作「共享」按鈕。最初,我遵循了developers.android.com上的建議,但得到了一個異常,說我需要使用MenuItemCompat。我這樣做,但現在我的分享按鈕甚至不會「點擊」。 我的相關代碼:ShareActionProvider從support.v7不點擊
public boolean onCreateOptionsMenu(Menu menu) {
Log.d("CYCLE:","onCreateOptionsMenu()");
// Inflate the menu; this adds items to the action bar if it is present.
getMenuInflater().inflate(R.menu.menu_to_do_list, menu);
// Locate MenuItem with ShareActionProvider
MenuItem item = menu.findItem(R.id.action_share);
// Fetch and store ShareActionProvider
mShareActionProvider = (ShareActionProvider) MenuItemCompat.getActionProvider(item);
setShareIntent();
mShareActionProvider.setShareHistoryFileName("my_share_history.xml");
return true;
}
public void setShareIntent(){
Intent shareIntent = new Intent(Intent.ACTION_SEND);
shareIntent.setType("text/plain");
shareIntent.putExtra(Intent.EXTRA_TEXT, "some text to share");
mShareActionProvider.setShareIntent(shareIntent);
}
和XML我的菜單項是:
<item android:id="@+id/action_share"
android:title="Share"
app:showAsAction="ifRoom"
app:actionProviderClass="android.support.v7.widget.ShareActionProvider"/>
我失去的東西,使這個按鈕可以點擊的? (我甚至沒有談論功能,只是點擊能力(你知道,就像點擊/點擊動畫一樣) 謝謝
在updateShareInfo()結束時調用setShareIntent()。 – Harry
我的不好,我粘貼了它並刪除了評論,其中我刪除了這個調用。代碼有點,但按鈕仍然不可點擊... – fiacobelli