ABS - ShareActionProvider: How to remove icon on right hand side

2,558 views
Skip to first unread message

tiptopjat

unread,
Jun 16, 2012, 7:26:46 PM6/16/12
to actionba...@googlegroups.com
I have implemented ShareActionProvider in my ABS.

When a user selects an app to share content with, eg Twitter, the actionbar displays a Twitter icon next to the Share button.

Does anybody know how to disable this?

Sven Meier

unread,
Jun 17, 2012, 5:06:02 AM6/17/12
to actionba...@googlegroups.com
Hi,

this is no ABS question but here's a solution anyway:

Implement OnShareTargetSelectedListener and set it on the
ShareActionProvider:

@Override
public boolean onShareTargetSelected(ShareActionProvider source,
Intent intent) {

context.startActivity(intent);

// started activity ourself to prevent search history
return true;
}

Now the selected share action will no longer appear in the search
history on the actionbar.

Hope this helps
Sven

tiptopjat

unread,
Jun 17, 2012, 6:53:40 AM6/17/12
to actionba...@googlegroups.com
Thanks for sharing this solution, but I can't get it to work.

Here's my code, should I modify anything in OnCreateOptionsMenu()?



public class MainActivity extends SherlockListActivity implements OnShareTargetSelectedListener {

        public onCreate....{}

        @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 actionItem = menu
.findItem(R.id.menu_item_share_action_provider_action_bar);
ShareActionProvider actionProvider = (ShareActionProvider) actionItem
.getActionProvider();
actionProvider.setShareHistoryFileName(ShareActionProvider.DEFAULT_SHARE_HISTORY_FILE_NAME);

//actionProvider.setShareIntent(createShareIntent());

return true;
}
public boolean onShareTargetSelected(ShareActionProvider source, Intent intent) {
// TODO Auto-generated method stub
this.startActivity(createShareIntent()); 

                 return true; 
}

private Intent createShareIntent() {
// Creates intent to share
intent = new Intent(Intent.ACTION_SEND);
intent.setType("text/plain");
intent.putExtra(Intent.EXTRA_TEXT,

return intent;
}

tiptopjat

unread,
Jun 17, 2012, 8:59:59 AM6/17/12
to actionba...@googlegroups.com
The main reason I would like to remove the application icon is because the icons have a grey border, which doesn't match my black actionbar. (http://imageshack.us/photo/my-images/155/20120617130029.jpg/). Do you know how I can change this from black to grey? I would be happy to keep the app icon on the action bar if I could change the grey colour.


On Sunday, June 17, 2012 10:06:02 AM UTC+1, Sven Meier wrote:

Sven Meier

unread,
Jun 17, 2012, 9:42:37 AM6/17/12
to actionba...@googlegroups.com
You have to set your listener on the action provider:

    actionProvider.setOnShareTargetSelectedListener(this);

Sven

tiptopjat

unread,
Jun 17, 2012, 10:03:05 AM6/17/12
to actionba...@googlegroups.com
That works perfectly! Thank you. 

Chris Ian Fiel

unread,
Feb 8, 2013, 4:06:12 AM2/8/13
to actionba...@googlegroups.com

I tried this solution but it does not work. the button cannot be press this is my code below. any idea what I am missing?

@Override
public boolean onCreateOptionsMenu(Menu menu) {
MenuInflater inflater = getSupportMenuInflater();
inflater.inflate(R.menu.tonesdetail, menu);

MenuItem actionItem = menu.findItem(R.id.share);
ShareActionProvider actionProvider = (ShareActionProvider) actionItem.getActionProvider();
actionProvider.setShareHistoryFileName(ShareActionProvider.DEFAULT_SHARE_HISTORY_FILE_NAME);
actionProvider.setOnShareTargetSelectedListener(this);

return true;
}

@Override 
        public boolean onShareTargetSelected(ShareActionProvider source, Intent intent) { 
               this.startActivity(createShareIntent()); 
        return true; 

        private Intent createShareIntent() {
       File file = new File(SharedPrefsConfig.SD_TONES+name+".mp3");
           Intent shareIntent = new Intent(Intent.ACTION_SEND);
           shareIntent.setType("audio/*");
           Uri uri =  Uri.fromFile(file);
           shareIntent.putExtra(Intent.EXTRA_STREAM, uri);
        return shareIntent;

තරිඳු ගුණවර්ධන

unread,
Aug 18, 2013, 4:06:22 AM8/18/13
to actionba...@googlegroups.com
Set the intent to your provider.
ShareActionProvider actionProvider = (ShareActionProvider) actionItem.getActionProvider();
actionProvider.setShareIntent(createShareIntent());
...

Then,
@Override 
        public boolean onShareTargetSelected(ShareActionProvider source, Intent intent) { 
               this.startActivity(intent); 
        return true; 

Prasanna Gunasekeran

unread,
Jun 2, 2014, 3:18:00 AM6/2/14
to actionba...@googlegroups.com
This solution is not at all woorking cant able to clik on share icon...
Anybody know the exact solution
Reply all
Reply to author
Forward
0 new messages