I'm using ActionBarSherlock in my project, and want to set a share button to post content at FB etc etc... I achieved that this way: Adding items to action bar (using ActionBarSherlock)
As you may know, ShareActionProvider adds a second icon with the most used option for sharing. That means another app's icon is appearing in my action bar, and I want to prevent that behavior... I've seen 2 possible solutions for that, and unfortunately both didn't worked to me :/
The first attempt was, in my target class, to implement OnShareTargetSelectedListener and override onShareTargetSelected method (like here: ActionBarSherlock - Share Content icon issue). But the extra icon stays there... here is my code:
@Override
public boolean onCreateOptionsMenu(Menu menu)
{
getSupportMenuInflater().inflate(R.menu.share, menu);
mShareActionProvider = (ShareActionProvider) menu.findItem(R.id.share).getActionProvider();
Intent intent = getDefaultShareIntent();
mShareActionProvider.setOnShareTargetSelectedListener(this);
if(intent!=null)
mShareActionProvider.setShareIntent(intent);
return super.onCreateOptionsMenu(menu);
}
@Override
public boolean onShareTargetSelected(ShareActionProvider source,
Intent intent) {
this.startActivity(intent);
// started activity ourself to prevent search history
return true;
}
The second attempt was to rewrite some classes from ActionBarSherlock, to prevent it from showing the extra icon (like here: How to hide the share action (which use most) icon near the share action provider?). But I got problems with this solution, as I couldn't import com.actionbarsherlock.widget.ActivityChooserModel from my custom classes (blocked to outer packages). Even copying this class to my package, it didn't worked (app crashes)...
Looks like its a pretty usual thing to disable this extra icon, but I couldn't figure out why the solutions above didn't worked to me...
Thanks in advance for any ideas and sugestions
I don't know if you resolved your problem but I had the same issue to remove history of ShareActionProvider
. I tried everything and the near answer I found was the same as you (How to hide the share action icon?).
After some researches, I found this trick on the second comment:
Action Bar Sherlock has depreciated methods
ShareActionProvider
, ActivityChooserView
and ActivityChooverModel
) from ABS to your package.if (activityCount > 0 && historySize > 0)
by if (false)
in your new ActivityChooserView
.android:actionProviderClass="com.myapp.ShareActionProvider"
Manifest
, make the minSdkVersion
equals to 11. Save your project. Clean it. Manifest
, replace your minSdkVersion
by the old one you used. Save and clean. It works perfectly. Let me know if this tip resolved your problem.