1

I am trying to use ShareActionProvider in my Android App. First I tried to use default ShareActionProvider. But unfortunately I found android not provides any method to change the color of share icon.

So I use ActionBarSherlock. I was able to change the background , but I am not able to remove the spaces around menu item and shareaction provider.

Secondly the right history icon.

Please help.

Here is the source code.

   protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setTheme(R.style.MyApp);
    setContentView(R.layout.activity_fullscreen);

    ActionBar actionBar = getSupportActionBar();
    actionBar.setHomeButtonEnabled(false);
    actionBar.setDisplayShowHomeEnabled(false);
    LayoutInflater inflator = (LayoutInflater) getSystemService(Context.LAYOUT_INFLATER_SERVICE);
    View custom = inflator.inflate(R.layout.actionbar_view, null);
    actionBar.setCustomView(custom);
    actionBar.setDisplayShowTitleEnabled(false);
    actionBar.setDisplayOptions(0, ActionBar.DISPLAY_SHOW_CUSTOM);
    actionBar.setDisplayShowCustomEnabled(true);

}

@Override
public boolean onCreateOptionsMenu(Menu menu) {

    getSupportMenuInflater().inflate(R.menu.menu, menu);

    MenuItem actionItem = menu.findItem(R.id.share_action_provider);
    ShareActionProvider actionProvider = (ShareActionProvider) actionItem.getActionProvider();
    actionProvider.setShareHistoryFileName(null);

    actionProvider.setShareIntent(createShareIntent());

    return true;
}

My style

<style name="MyApp" parent="Theme.Sherlock.Light.DarkActionBar">
<item name="windowActionBarOverlay">true</item> <!-- for ActionBarSherlock -->
</style>

My Menu XML

<?xml version="1.0" encoding="utf-8"?>
 <menu xmlns:android="http://schemas.android.com/apk/res/android" >
 <item android:id="@+id/contest"
    android:showAsAction="always"
    android:icon="@drawable/contest" />
 <item android:id="@+id/share_action_provider"
    android:showAsAction="always"
    android:actionProviderClass="com.actionbarsherlock.widget.ShareActionProvider" />
</menu>

My Custom View

<RelativeLayout 
android:id="@+id/actionLayout"
android:layout_width="match_parent"
android:layout_height="match_parent">
   <ImageView
   android:id="@+id/homeIcon"
   android:layout_width="wrap_content"
   android:layout_height="wrap_content"
   android:src="@drawable/home_button_background"
   android:layout_alignParentLeft="true"
   android:onClick="onHomeClick">
   </ImageView>
</RelativeLayout> 

Here is the screenshot.

enter image description here

mmBs
  • 8,421
  • 6
  • 38
  • 46
vineet
  • 269
  • 1
  • 4
  • 18
  • You need to remove the right icon (most selected icon) that's it? You need to check these tips: http://stackoverflow.com/questions/10706564/how-do-you-turn-off-share-history-when-using-shareactionprovider - and mainly http://stackoverflow.com/a/17290249/2668136 - http://stackoverflow.com/a/20550542/2668136 For the space around the icon, I didn't find anything, but once your right icon disappear, you will able to have no spaces. – Blo Dec 13 '13 at 04:35

1 Answers1

0

You need to make changes in default style as mentioned below :

<style name="MyApp" parent="Theme.Sherlock.Light.DarkActionBar">
<item name="windowActionBarOverlay">true</item> <!-- for ActionBarSherlock -->

<!-- add following items -->
    <item name="actionButtonStyle">@style/CustomActionButtonStyle</item>
    <item name="android:actionButtonStyle">@style/CustomActionButtonStyle</item>
</style>

<style name="CustomActionButtonStyle" parent="Widget.Sherlock.ActionButton">
    <item name="android:minWidth">32dip</item>
    <item name="android:padding">0dip</item>
</style>

The reason behind this issue is the default value of android:minWidth for the ActionBar buttons which is 56dip , so you need to change it.

I hope it will be helpful !!

Mehul Joisar
  • 15,348
  • 6
  • 48
  • 57