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.