Android - Icon not shown in AlertDialog

android

Solution

You should use something like this:

builder.setIcon(getResources().getDrawable(android.R.drawable.ic_dialog_alert));

Try this :)

Problem

I have an alert dialog that does not show the icon that I set using "setIcon". I use Android Studio and Android Emulator API 19/ Android 4.4.2. I can run the app, the dialog is shown without icon, no error. But Android studio marks the line that contains "setIcon" and offers me "Introduce local variable" and "Make method call chain into call sequence" So my question : Why is the icon not shown? My Code: ``` AlertDialog.Builder builder = new AlertDialog.Builder(this ); builder .setMessage("Repeat game?") .setIcon(android.R.drawable.ic_dialog_alert) //<--- icon does not show .setPositiveButton("Yes", new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialog, int which) { //Yes button clicked, do something } }) .setNegativeButton("No", null) //Do nothing on no .show(); ```

Original source

Related problems