1

I want to set an Image and two buttons in an alert dialog ,i have tried the below code,i can set the image ,but i don't know how to set icon's for buttons.And i also want to align first button on the bottom of another button like this screen shot.

I have tried this code to add an image

 public void showAlert()
 {
AlertDialog.Builder alertadd = new AlertDialog.Builder(
        MainActivity.this);

LayoutInflater factory = LayoutInflater.from(MainActivity.this);
final View view = factory.inflate(R.layout.alertimage, null);
alertadd.setView(view);
alertadd.setNeutralButton("Here!", new DialogInterface.OnClickListener() {
    public void onClick(DialogInterface dlg, int sumthin) {

    }
});

alertadd.show();
}
Tom
  • 296
  • 6
  • 22
  • try creating custom class for dialog fragment and set it over there – karan Jul 29 '15 at 09:52
  • or you can create theme for dialog as shown here http://stackoverflow.com/questions/24691192/replace-button-background-of-android-dialogfragment – karan Jul 29 '15 at 09:55
  • to create custom dialog see this http://stackoverflow.com/questions/13341560/how-to-create-a-custom-dialog-box-in-android – karan Jul 29 '15 at 09:55

3 Answers3

2

Try this in the XML layout file:

<Button
...
android:drawableLeft="@drawable/source" />

Or, you could do programmatically as:

mButton.setCompoundDrawablesWithIntrinsicBounds( R.drawable.source, 0, 0, 0);
Andro
  • 952
  • 9
  • 19
  • can you give an example please? – Tom Jul 30 '15 at 00:32
  • In your case do something like this after `alertAdd.show();` `Button neutralButton= alertAdd.getButton(DialogInterface.BUTTON_NEUTRAL); neutralButton.setCompoundDrawablesWithIntrinsicBounds( R.drawable.source, 0, 0, 0);` – Andro Jul 30 '15 at 06:50
0

I suggest you create the layout u want (R.layout.alertimage) with the image and the buttons already inside, than inflate it to the dialog(and dont use the alert dialogs buttons). than u can use alertadd.findviewbyid(R.id.button).setonclicklistener(...)

Wops
  • 983
  • 9
  • 23
0

I have solved the problem using a simple Popup window.It works fine.

Tom
  • 296
  • 6
  • 22