Reputation: 1078
Hey I'm trying to put an image above the title in the alert dialog. This is what I'm doing:
ImageView image = new ImageView(this);
image.setImageResource(R.drawable.img);
alertDialog = new AlertDialog.Builder(new ContextThemeWrapper(this, android.R.style.Theme_DeviceDefault_Light_Dialog))
.setView(image)
.setCancelable(false)
.setTitle(title)
.setMessage(message)
.setPositiveButton(btn1, new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int whichButton) {}})
.setNegativeButton(btn2, new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int whichButton) {}})
.create();
alertDialog.show();
And This is what I'm trying to achieve:
I've also tried it with setIcon but then the image appears on the left of the title and not above.
Upvotes: 1
Views: 1268
Reputation: 795
Simply use this solution
final Dialog dialog = new Dialog(this);
dialog.requestWindowFeature(Window.FEATURE_LEFT_ICON);
dialog.setTitle(R.string.my_dialog_title);
dialog.setContentView(R.layout.my_dialog_layout);
dialog.setFeatureDrawableResource(Window.FEATURE_LEFT_ICON,R.drawable.some_icon);
dialog.show();
Upvotes: 1
Reputation: 574
You have to create custom dialog and inflate that layout for CustomDialog. You can view Custome dialog here.
Upvotes: 0
Reputation:
You have to create custom layout in which you can design which you want. Becuase you can not more customization in default existing alert dialog.
Custom Alert dialog you can create with ref url : http://javatechig.com/android/android-custom-dialog-example
Upvotes: 0