virtualdj
virtualdj

Reputation: 479

Hide the share action icon near the share action provider WITHOUT ActionBarSherlock

I'm quite new to Android development and I'm trying to build an ActionBar with the ShareActionProvider, using the "stock" ActionBar (i.e. not using ActionBarSherlock), because I want to target ICS+ devices only.

I would like the history function enabled (as it is by default), but I don't want the most used intent icon near the share button, because it takes too much space.
I know that using ActionBarSherlock this is possible, but as I said I'm trying to do it with the stock ActionBar, so I would like to know how to overcome to this problem.

I've found these two related answers:
How to hide the share action (which use most) icon near the share action provider?
Android: ShareActionProvider with no history

but none of them clearly say how to edit the Android sources to have another "version" of the ActionBar that hides the icon.
I mean, how can I combine the two answers and ship my application with the modified ActionBar class that hides the most-used icon?

EDIT:
I'm looking for a brief list of operations that have to be done to extend the three classes ShareActionProvider, ActivityChooserView and ActivityChooserMode to build a modified version of them that doesn't raise errors in Eclipse. AFAIK this is not documented elsewhere on the web (Google doesn't give results).

Upvotes: 2

Views: 2719

Answers (2)

Dhruva Bharadwaj
Dhruva Bharadwaj

Reputation: 101

  1. Copy source files ActivityChooserView.java and ShareActionProvider.java files from https://android.googlesource.com/platform/frameworks/support.git into your project.
  2. Do a Ctrl+Shift+O on eclipse on both the files to fix up any imports. In your ShareActionProvider.java, change the import for ActivityChooserView.java to the new file.
  3. Change import ShareActionProvider in the file in which you have implemented onCreateOptionsMenu() to the location to where you copied this file.
  4. In menu.xml, correct the ShareActionProvider class to the new one.
  5. Look for if( activityCount==1 || activityCount > 1 && historySize > 0 ) in ActivityChooserView.java. change it to if(false)

You're all set!

Upvotes: 0

CommonsWare
CommonsWare

Reputation: 1006614

but none of them clearly say how to edit the Android sources to have another "version" of the ActionBar that hides the icon.

That is because you do not change the action bar. You change the ShareActionProvider. If you do not like the existing implementation of ShareActionProvider, create your own, perhaps using the existing implementation as a starting point.

For example, that is what the accepted answer on the Android: ShareActionProvider with no history question describes. Neither the question nor the answer reference ActionBarSherlock.

Upvotes: 1

Related Questions