user_s
user_s

Reputation: 1078

Android alert dialog - image on top

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();

This is the result : enter image description here

And This is what I'm trying to achieve: enter image description here

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

Answers (3)

Lan Nguyen
Lan Nguyen

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

androgo
androgo

Reputation: 574

You have to create custom dialog and inflate that layout for CustomDialog. You can view Custome dialog here.

Create Custom dialog

Upvotes: 0

user4571931
user4571931

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

Related Questions