How to change size custom dialog

I use custom dialog in android. I want changed size custom dialog in all screen , But this is at all screen one size. I used 2 class for custom dialog :

  1. To bind xml file to the custom dialog
  2. for show custom dialog

this is class for show custom dialog:

public class mh_show_dialog {

public Button yes , no;

private TextView txt;

private Context context ;

final mh_alert_dialog dialog; 

public mh_show_dialog(Context co)
{
    this.context = co;
    dialog = new mh_alert_dialog(context);
}

public void dialog_text(String message , String btn_yes , String btn_no , String image_title)
{

    dialog.set_text(message,btn_yes,btn_no);
    dialog.set_image(image_title);

    yes = (Button) dialog.findViewById(R.id.alert_yes);
    no = (Button) dialog.findViewById(R.id.alert_no);

    txt = (TextView) dialog.findViewById(R.id.alert_msg);

    no.setOnClickListener(new Button.OnClickListener() 
    {
        public void onClick(View v)     {
            dialog_dismiss();
        }
    });
    dialog.show();
}

public void dialog_dismiss()
{
    dialog.dismiss();
}

public void False_visible_btn_no()
{
    no.setVisibility(View.INVISIBLE);
}

}

Please help me.

Upvotes: 0

Views: 3913

Answers (1)

Himanshu Shekher Jha
Himanshu Shekher Jha

Reputation: 1344

your problem is "I use custom dialog in android. I want changed size custom dialog in all screen ". you can do several things.

  1. Change your layout file size.

    You need to change the layout "R.layout.alert_dialog", and change the layout size according to your requirement. if you need more help, then show me your XML layout file.

  2. Set Size at Runtime(In your DialogHelper java file) check this answer

    https://stackoverflow.com/a/6922903/4876386

updated answer.... if you want to get dynamic size Dialog box at different place , then you need to create a function in which you specify the height and width of your dialog box at run time.Use this function in your custom Dialog code, give size of width & height at run time.

public void showInfoAlertDialog(Context context, String message,int height, int width) {
        AlertDialog.Builder alertDialog = new AlertDialog.Builder(context);

        // Setting Dialog Message
        alertDialog.setMessage(message);

        // Setting OK Button
        alertDialog.setPositiveButton("OK",
                new DialogInterface.OnClickListener() {
                    public void onClick(DialogInterface dialog, int which) {
                    }
                });

        // Showing Alert Message
        AlertDialog alert = alertDialog.show();
        TextView messageText = (TextView) alert
                .findViewById(android.R.id.message);
        messageText.setGravity(Gravity.CENTER);

        alert.show();
        alertDialog.getWindow().setLayout(width, hight);
    }

Update 4:

now change your code at two location,

Upvotes: 1

Related Questions