Android Dialog theme makes icon too light Android Dialog theme makes icon too light android android

Android Dialog theme makes icon too light


The problem is that you are using private resource android.R.drawable.ic_dialog_alert.

Using private resources is problematic, they can vary on different devices and you can't even be sure that they are present on all devices. The best is to avoid using private resources. If you need them, you should copy them from Android sources and put them in your project's resources.

The exact reason why your resource is too white is that you are using resource (android.R.drawable.ic_dialog_alert) that is used for standard (non-Holo) theme.
But for devices running Android 4.x (API level 14) you are using Holo theme (android:Theme.Holo.Light.DarkActionBar) which is normally using different resource.

With Holo theme the default alert icon is android.R.id.ic_dialog_alert_holo_dark for the dark theme or android.R.id.ic_dialog_alert_holo_light for the light theme (your case, you should use this resource instead).

Note: Since API level 11 there is an attribute android.R.attr.alertDialogIcon which refers to the default alert dialog icon for the current theme. In your code you can use it this way:

case R.id.menu_quit:    new AlertDialog.Builder(this)    .setIconAttribute(android.R.attr.alertDialogIcon)    .setTitle(R.string.confirm_title)    .setMessage(R.string.confirm_text)    .setPositiveButton(R.string.ok, new DialogInterface.OnClickListener() {        @Override        public void onClick(DialogInterface dialog, int which) {            finish();            }

Still I recommend to copy the resource from Android sources to your project's resources because that's the only way you can be sure that the icon will always look the same.


A workround based on Tomik's answer for pre-HC if you're using light theme on those devices too:

AlertDialog.Builder builder = ...;if (VERSION.SDK_INT < VERSION_CODES.HONEYCOMB) {    Drawable icon = ContextCompat.getDrawable(context, android.R.drawable.ic_dialog_alert).mutate();    icon.setColorFilter(new ColorMatrixColorFilter(new float[] {            -1, 0, 0, 0, 255, // red = 255 - red            0, -1, 0, 0, 255, // green = 255 - green            0, 0, -1, 0, 255, // blue = 255 - blue            0, 0, 0, 1, 0     // alpha = alpha    }));    builder.setIcon(icon);} else {    builder.setIconAttribute(android.R.attr.alertDialogIcon);}