0

Currently i have a dialog that shows an image that is being clicked by the user.

What i want to do, is to add a button on the bottom of the dialog.

This is my current code:

  public void showImage(Drawable drawable) {
        final Dialog builder = new Dialog(mContext);
        builder.setCancelable(true);
        builder.setCanceledOnTouchOutside(true);
        builder.requestWindowFeature(Window.FEATURE_NO_TITLE);
        builder.getWindow().setBackgroundDrawable(
                new ColorDrawable(Color.RED));

//        builder.getWindow().setBackgroundDrawable(
//                new ColorDrawable(android.graphics.Color.TRANSPARENT));
        builder.setOnDismissListener(new DialogInterface.OnDismissListener() {
            @Override
            public void onDismiss(DialogInterface dialogInterface) {
                //nothing;
            }
        });

        ImageView imageView = new ImageView(mContext);
        Button mClose = new Button(mContext);
        mClose.setText("CLOSE");
        mClose.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                builder.dismiss();
            }
        });
        imageView.setImageDrawable(drawable);
        builder.addContentView(imageView, new RelativeLayout.LayoutParams(
                ViewGroup.LayoutParams.WRAP_CONTENT,
                ViewGroup.LayoutParams.WRAP_CONTENT));
        builder.addContentView(mClose,new RelativeLayout.LayoutParams(
                ViewGroup.LayoutParams.MATCH_PARENT,
                ViewGroup.LayoutParams.WRAP_CONTENT));
        builder.show();
    }

The current code have : The button is in the upper left of the imageview where it should be on the below of imageview.

Gautam Surani
  • 1,136
  • 10
  • 21

2 Answers2

1

Try This

afer

builder.addContentView(mClose,new RelativeLayout.LayoutParams(
                ViewGroup.LayoutParams.MATCH_PARENT,
                ViewGroup.LayoutParams.WRAP_CONTENT));

Add This

RelativeLayout.LayoutParams lp=new RelativeLayout.LayoutParams(
                    ViewGroup.LayoutParams.MATCH_PARENT,
                    ViewGroup.LayoutParams.WRAP_CONTENT)

    lp.addRule(RelativeLayout.ALIGN_PARENT_BOTTOM);

//yourButton

    builder.addContentView(yourButton,lp));
Ashvin solanki
  • 4,802
  • 3
  • 25
  • 65
0

Better to create your own custom dialog and show image and button.

Please look into below similar links, this might help you.

How to make a pop up image like an advertisement? [Android]

Show AlertDialog with ImageView without any padding

Thanks

Sreepal
  • 11
  • 1