Skip to content

Instantly share code, notes, and snippets.

@briangriffey
Last active June 17, 2016 17:03
Show Gist options
  • Save briangriffey/11185716 to your computer and use it in GitHub Desktop.
Save briangriffey/11185716 to your computer and use it in GitHub Desktop.
How to change an icon on the shareactionprovider
package com.wahtever.views.actionbar;
import android.content.Context;
import android.graphics.drawable.Drawable;
import android.view.View;
import android.widget.ShareActionProvider;
import com.whatever.R;
import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;
/**
* Created by briangriffey on 4/22/14.
*/
public class ShareProvider extends ShareActionProvider {
private final Context mContext;
/**
* Creates a new instance.
*
* @param context Context for accessing resources.
*/
public ShareProvider(Context context) {
super(context);
mContext = context;
}
@Override
public View onCreateActionView() {
View chooserView =
super.onCreateActionView();
// Set your drawable here
Drawable icon =
mContext.getResources().getDrawable(R.drawable.ic_share);
Class clazz = chooserView.getClass();
//reflect all of this shit so that I can change the icon
try {
Method method = clazz.getMethod("setExpandActivityOverflowButtonDrawable", Drawable.class);
method.invoke(chooserView, icon);
} catch (NoSuchMethodException e) {
e.printStackTrace();
} catch (InvocationTargetException e) {
e.printStackTrace();
} catch (IllegalAccessException e) {
e.printStackTrace();
}
return chooserView;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment