0

I want to change the icon of share item in action bar.

Here is my menu file:

<item
    android:id="@+id/menu_item_share"
    app:showAsAction="always"
    android:title="@string/menu_share"
    app:actionProviderClass="android.support.v7.widget.ShareActionProvider"
    />
<item>

My activity which extends ActionBarActivity:

import android.support.v7.widget.ShareActionProvider;   

private ShareActionProvider mShareActionProvider;

@Override
public boolean onCreateOptionsMenu(Menu menu) {
    MenuInflater menuInflater = getMenuInflater();
    menuInflater.inflate(R.menu.main_menu, menu);

    // Locate MenuItem with ShareActionProvider
    MenuItem item = menu.findItem(R.id.menu_item_share);

    // Fetch and store ShareActionProvider
    mShareActionProvider = (ShareActionProvider) MenuItemCompat.getActionProvider(item);

    Intent shareIntent = new Intent(Intent.ACTION_SEND)
            .putExtra(Intent.EXTRA_TEXT, "text")
            .setType("text/plain");
    mShareActionProvider.setShareIntent(shareIntent);
    return true;
}

I tried to change the styles file:

<!-- Base application theme. -->
<style name="AppTheme" parent="Theme.AppCompat.Light">
    <item name="android:windowNoTitle">true</item>
    <item name="windowActionBar">false</item>
    <item name="android:windowFullscreen">true</item>
    <item name="android:windowContentOverlay">@null</item>
    <item name="android:actionBarWidgetTheme">@style/Theme.AppCompat.CustomShareIcon</item>
</style>

  <!-- Custom Share Icon -->
<style name="Theme.AppCompat.CustomShareIcon" parent="@style/Theme.AppCompat">
    <item name="android:actionModeShareDrawable">@drawable/share</item>
</style>

But I got android:actionModeShareDrawable requires API level 21 so I moved the code to v21/styles but still it does not work.

I also tried to create custom share provider Setting a custom share icon on Actionbar ShareActionProvider without ActionBarSherlock but I got java.lang.ClassCastException.

Community
  • 1
  • 1
rerashhh
  • 1,671
  • 1
  • 13
  • 15
  • refer my [Answer](http://stackoverflow.com/questions/29145956/theme-for-searchview-in-actionbar/29159952#29159952). Vote up if you like it. – Harin Apr 14 '15 at 09:34
  • Oh! sorry, you can't change with given share action provider as it has its own implementation, you can create your own action like [Cusom Action Provider](http://wptrafficanalyzer.in/blog/creating-custom-action-provider-in-action-bar/) with popup menu on click event. – Harin Apr 14 '15 at 10:37
  • i had to change from menu.xml the action provider class and it worked but now it looks to big, the others are smaller than share icon. if i leave it like normal items it looks good..do you have any ideas to make it look normal? – rerashhh Apr 14 '15 at 10:57
  • apply padding in image view. – Harin Apr 14 '15 at 11:03
  • it didn't work. so i leaved it like a normal menu item and i added http://stackoverflow.com/questions/17167701/how-to-activate-share-button-in-android-app – rerashhh Apr 14 '15 at 11:37
  • Check this: http://stackoverflow.com/questions/10832108/setting-a-custom-share-icon-on-actionbar-shareactionprovider – Ariel Vila Jul 21 '15 at 14:56

1 Answers1

0

it worked for me...Add android:icon in ur xml:

Example:

<item
android:id="@+id/action_share"
android:title="Share"
android:icon="@drawable/ic_share_menu"
app:actionProviderClass="android.support.v7.widget.ShareActionProvider"
app:showAsAction="always"
android:orderInCategory="100">
</item>