This question is a bit outdated, but I decided to give an answer because I ran into the same problem today, and setting the activity topic was not a satisfactory answer for my use case. If you need only one specific close icon for each action, it is preferable to set actionModeCloseDrawable in the theme for this action. However, if you need several closing icons for the action modes in an exercise, it becomes necessary to use reflection to change the ImageView drawing being closed:
/** * Attempts to change the ActionMode close icon drawable using reflection. * * @param drawableResId * Resource ID of the new drawable * * @return true if the drawable was changed, false otherwise. */ private boolean setActionCloseDrawable(@Nullable final ActionMode actionMode, final int drawableResId) { if (actionMode != null) { // Change the drawable for the close ImageView to the desired icon // Unfortunately, this can only be done with reflection try { final Field wrappedObjectField = actionMode.getClass().getDeclaredField("mWrappedObject"); wrappedObjectField.setAccessible(true); final Object mWrappedObject = wrappedObjectField.get(actionMode); final Field contextViewField = mWrappedObject.getClass().getDeclaredField("mContextView"); contextViewField.setAccessible(true); final Object mContextView = contextViewField.get(mWrappedObject); final Field closeField = mContextView.getClass().getDeclaredField("mClose"); closeField.setAccessible(true); final Object mClose = closeField.get(mContextView); if (mClose instanceof ImageView) { ((ImageView) mClose).setImageDrawable(getResources().getDrawable(drawableResId)); return true; } } catch (Exception ex) { Log.e(TAG, ex.getClass().getSimpleName() + " in #setActionCloseDrawable: " + ex.getLocalizedMessage() + '\n' + Log.getStackTraceString(ex)); } } return false; }
source share