Alex Rivera | Logout

Setting a custom share icon on Actionbar ShareActionProvider

Asked 2012-05-31T10:48:34.800
15

I'm trying to set the icon ShareActionProvider, need a solid white one instead of the semi transparent white one.

However setting in share_menu.xml and code doesn't work. Just wondering whether anyone has got workaround for this before extending the ShareActionProvider. (I'm using actionbarsherlock)

@Override
public void onCreateOptionsMenu(final Menu menu, final MenuInflater inflater) {
    inflater.inflate(R.menu.share_menu, menu);
    MenuItem actionItem = menu.findItem(R.id.share_action_provider);

    ShareActionProvider actionProvider = (ShareActionProvider) actionItem.getActionProvider();
     actionProvider.setShareIntent(mShareIntent);

    // re-setting the icon as it's not being picked up from the menu xml file
    actionItem.setIcon(R.drawable.ic_action_share);

    super.onCreateOptionsMenu(menu, inflater);

}

share_menu.xml

 <item android:id="@+id/share_action_provider"
        android:showAsAction="ifRoom"
        android:title="@string/share_with"
        android:icon="@drawable/ic_action_share"
        android:actionProviderClass="com.actionbarsherlock.widget.ShareActionProvider" />

Update: Also tried setting it in the style, but no joy

<style name="Theme.MyApp" parent="Theme.Sherlock.Light">
        <item name="actionModeStyle">@style/ActionModeStyle</item>
        <item name="android:actionModeStyle">@style/ActionModeStyle</item>
</style>

<style name="ActionModeStyle" parent="Widget.Sherlock.ActionMode">
      <item name="actionModeShareDrawable">@drawable/ic_action_share</item>
  </style>
Edit
Report

1 Answer

1

You can override the non-public attribute like this.

<style name="Theme.MyApp" parent="android:Theme.Holo">
        <item name="*android:actionModeShareDrawalbe">@drawable/icon</item>
</style>

(*) means reference to the non-public resources in Android

answered 2012-11-18T18:08:34.990

Your Answer