I am using an action bar with the latest sdk and api (4.4.2). I am using my own theme; custom black and white. I cannot figure out how to change the default "back" and "share" icons. They are a greyish, I want it to be pure black. How can I do this? Other questions and answers posted ain't helping.
I tried using and setting a drawable for the share icon but it doesn't change... I have no idea how to change the back button as well.
<item
android:id="@+id/share_option"
android:actionProviderClass="android.widget.ShareActionProvider"
android:showAsAction="ifRoom"
<!-- android:icon="@drawable/action_share" | This doesn't do the trick -->
android:title="@string/Share"/>
The "up" indicator can be themed using the attribute android:homeAsUpIndicator
.
The ShareActionProvider
icon can be themed using the attribute *android:actionModeShareDrawable
. It's important that you include the *
prefix because this attribute isn't public.
But if you're using Theme.Holo.Light.DarkActionBar
, you'll have to subclass ShareActionProvider
and use reflection to change the icon.
Here are examples for both cases:
Using a theme
<style name="Your.Theme" parent="@android:style/Theme.Holo.Light">
<item name="android:homeAsUpIndicator">@drawable/your_up_indicator</item>
<item name="*android:actionModeShareDrawable">@drawable/your_share_icon</item>
</style>
Using reflection
public class YourShareActionProvider extends ShareActionProvider {
private final Drawable mYourShareIcon;
/**
* Constructor for <code>YourShareActionProvider</code>
*
* @param context The {@link Context} to use
*/
public YourShareActionProvider(Context context) {
super(context);
mYourShareIcon = context.getResources().getDrawable(R.drawable.your_share_icon);
}
@Override
public View onCreateActionView(MenuItem forItem) {
final View actionView = super.onCreateActionView(forItem);
try {
final Class<?> acv = Class.forName("android.widget.ActivityChooserView");
final Method setExpandActivityOverflowButtonDrawable = acv.getMethod(
"setExpandActivityOverflowButtonDrawable", Drawable.class);
setExpandActivityOverflowButtonDrawable.invoke(actionView, mYourShareIcon);
} catch (final Exception ignored) {
// Nothing to do
}
return actionView;
}
}
MenuItem
<item
android:id="@+id/share_option"
android:actionProviderClass="your.path.to.YourShareActionProvider"
android:showAsAction="ifRoom"
android:title="@string/Share"/>
Results