Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Invisible ActionMode item icons in Theme.Sherlock.Light.DarkActionBar

When using Theme.Sherlock.Light.DarkActionBar (or Theme.Holo.Light.DarkActionBar, doesn't make a difference), the ActionMode (or "contextual ActionBar") that appears for example when selecting text, is by default styled the same way as in the standard dark theme, that is dark blue with light action icons.

However, when you try to select a text in a Dialog (which is light-styled in this theme, in contrast to the black ActionBar), an ActionMode styled as in the Light theme (white background) appears instead. The problem is, that its action icons are not dark as they should be, but light, making them effectively invisible.

enter image description here

This seems as if the background was taken from the light theme (because of the light dialog), but the icons were taken from the dark theme. Is this a bug in the Light.DarkActionBar theme? Can I do something about it?

like image 849
Natix Avatar asked Nov 02 '13 12:11

Natix


2 Answers

I was fighting with the same issue since last two days. Finally I came up with a workaround!

I am using a DialogFragment with an AlertDialog object. In the onCreateDialog() method, all we have to do is get the context of the parent activity and set its theme again to Theme.Light.

@Override
public Dialog onCreateDialog(Bundle savedInstanceState) {
    //get the parent activity context and set it's theme again.
    Context ctx = getActivity();
    ctx.setTheme(android.R.style.Theme_Holo_Light);
    AlertDialog.Builder builder = new AlertDialog.Builder(ctx);
    LayoutInflater inflater = (LayoutInflater) ctx.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
    View view = inflater.inflate(R.layout.your_dialog_layout, null, false);
    builder.setView(view);

    //your other code for the dialog
    //

    return builder.create();

Now the icons in the Contextual ActionBar of the EditText have the right color.

like image 169
Basant Singh Avatar answered Oct 08 '22 18:10

Basant Singh


Forcing setTheme on the current context is not a good idea, as it corrupts the theme. To solve that you can use ContextThemeWrapper.

Context themedContext = new ContextThemeWrapper(getActivity(), android.R.style.Theme_Holo_Light);
final AlertDialog dialog = new AlertDialog.Builder(themedContext)
like image 21
AlexM Avatar answered Oct 08 '22 18:10

AlexM