I have the same problem as was described here - Setting a custom share icon on Actionbar ShareActionProvider
But I'am not using ActionBarSherlock
I found that the Sherlock theme uses the "actionModeShareDrawable" and I can also use it like this, if I don't use ActionBarSherlock
<style name="Theme.MyApp" parent="android:Theme.Holo">
<item name="*android:actionModeShareDrawable">@drawable/icon</item>
</style>
This works fine on my nexus 5, but failed on many other devices
So my question is, how to change that icon without using ActionBarSherlock
You can subclass ShareActionProvider, overriding only the constructor and createActionView().
From here, you can get the View from super, casting it to ActivityChooserView so you can call setExpandActivityOverflowButtonDrawable(Drawable) to change the icon.
package com.yourpackagename.whatever;
import android.content.Context;
import android.graphics.drawable.Drawable;
import android.support.v7.internal.widget.ActivityChooserView;
import android.support.v7.widget.ShareActionProvider;
import android.view.View;
import com.yourpackagename.R;
public class CustomShareActionProvider extends ShareActionProvider {
private final Context mContext;
public CustomShareActionProvider(Context context) {
super(context);
mContext = context;
}
@Override
public View onCreateActionView() {
ActivityChooserView chooserView =
(ActivityChooserView) super.onCreateActionView();
// Set your drawable here
Drawable icon =
mContext.getResources().getDrawable(R.drawable.ic_action_share);
chooserView.setExpandActivityOverflowButtonDrawable(icon);
return chooserView;
}
}
I like PrplRugby's answer, but you have to include the ActivityChooserView in your app. I refactored to use reflection which you can find here: https://gist.github.com/briangriffey/11185716
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With