Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Remove extra icon at actionbar (when using ShareActionProvider and ActionBarSherlock)

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

like image 659
Lucas Jota Avatar asked Oct 22 '22 00:10

Lucas Jota


1 Answers

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

  1. Copy/Paste the 3 classes (ShareActionProvider, ActivityChooserView and ActivityChooverModel) from ABS to your package.
  2. Replace the import by yours with your own package.
  3. Change the line if (activityCount > 0 && historySize > 0) by if (false) in your new ActivityChooserView.
    (You will get an error: "setActived" is not available for your current version)
  4. Save it and close the class.
  5. Replace the class in your menu.xml your item by android:actionProviderClass="com.myapp.ShareActionProvider"
  6. In your Manifest, make the minSdkVersion equals to 11. Save your project. Clean it.
  7. Return to your 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.

like image 136
Blo Avatar answered Oct 24 '22 03:10

Blo