ShareActionProvider with one icon - looks like a simple actionitem

I want to dislay ShareActionProvideron ActionBar, but with a custom look and feel. Only one simple sharing icon without borders and without much use the application icon on the right. But providing a popup menu with most used apps. Is there an easy way to do this without implementing my own ShareActionProvider?

+5
source share
1 answer

OK, therefore, regardless of the first ActionBarSherlock test, to make sure you created your intent correctly, ABS uses the same code as the general selector, so see if the application you're looking for appears when you run this code.

Intent I= new Intent(Intent.ACTION_SEND);
I.setType("text/plain");
I.putExtra(android.content.Intent.EXTRA_TEXT, "My Test Text");

startActivity(Intent.createChooser(I,"Share using ..."));

, , , facebook , , , ACTION_SEND (plain/text). (Facebook , )

, , ( ), , - -

@Override
    public boolean onCreateOptionsMenu(Menu menu) {
    // Inflate your menu.
    getSupportMenuInflater().inflate(R.menu.share_action_provider, menu);

// Set file with share history to the provider and set the share intent.
MenuItem item = menu.findItem(R.id.menu_item_share_action_provider_action_bar);
ShareActionProvider provider = (ShareActionProvider) item.getActionProvider();
              provider.setShareHistoryFileName(ShareActionProvider.DEFAULT_SHARE_HISTORY_FILE_NAME);
// Note that you can set/change the intent any time,
// say when the user has selected an image.
provider.setShareIntent(createShareIntent());

return true
}

,

private Intent createShareIntent() {
        Intent shareIntent = new Intent(Intent.ACTION_SEND);
        shareIntent.setType("image/plain");
        Uri uri = Uri.fromFile(getFileStreamPath("shared.png"));
        shareIntent.putExtra(Intent.EXTRA_STREAM, uri);
        shareIntent.putExtra(Intent.EXTRA_TITLE, "This is an android icon");
        return shareIntent;
    }

,

private Intent createShareIntent() {
        Intent I= new Intent(Intent.ACTION_SEND);
        I.setType("text/plain");
        I.putExtra(android.content.Intent.EXTRA_SUBJECT, "TEST - Disregard");
        I.putExtra(android.content.Intent.EXTRA_TEXT, Uri.parse("http://noplace.com"));
    }

ABS, , .

-1

All Articles