I am aware of android:actionModeBackground
that can be used in XML themes.
Is there a way to set this background in code?
Basically I need the ActionMode equavalent of
getActionBar().setBackgroundDrawable(drawable);
I figured out with reflection help. Because I dont have an actionbar
public static void setActionModeBackgroundColor(ActionMode actionMode, int color) {
try {
StandaloneActionMode standaloneActionMode = (StandaloneActionMode) actionMode;
Field mContextView = StandaloneActionMode.class.getDeclaredField("mContextView");
mContextView.setAccessible(true);
Object value = mContextView.get(standaloneActionMode);
((View) value).setBackground(new ColorDrawable(color));
} catch (Throwable ignore) {
}
}
Also there are 2 implementations of ActionMode : StandaloneActionMode and ActionModeImpl. this example only for First one. For second one it will be same
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