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.
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?
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.
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)
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