Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?xml version="1.0" encoding="utf-8"?>
- <menu xmlns:android="http://schemas.android.com/apk/res/android"
- xmlns:app="http://schemas.android.com/apk/res-auto">
- <item android:id="@+id/action_share"
- android:title="@string/share"
- app:showAsAction="always"
- app:actionProviderClass="android.support.v7.widget.ShareActionProvider"/>
- <item android:id="@+id/about"
- android:title="@string/about"
- app:showAsAction="never"/>
- </menu>
- // Locate MenuItem with ShareActionProvider
- MenuItem item = menu.findItem(R.id.action_share);
- // Fetch and store ShareActionProvider
- mShareActionProvider = (ShareActionProvider) MenuItemCompat.getActionProvider(item);
- return true;
- }
- private void setShareIntent() {
- Intent myShareIntent = new Intent(Intent.ACTION_SEND);
- myShareIntent.setType("text/plain");
- myShareIntent.putExtra(Intent.EXTRA_TEXT, "some text");
- mShareActionProvider.setShareIntent(myShareIntent);
- startActivity(myShareIntent);
- }
- @Override
- public boolean onOptionsItemSelected(MenuItem item) {
- // Handle item selection
- switch (item.getItemId()) {
- case R.id.action_share:
- setShareIntent();
- break;
- ....
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement