Jack D
Jack D

Reputation: 129

hello how can i make full width dialog popup in android this is my code

view.findViewById(R.id.doc_prof_det_add_speciality_btn).setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                AlertDialog.Builder alertDialog = new AlertDialog.Builder(v.getContext());
                LayoutInflater factory = LayoutInflater.from(v.getContext());
                final View view = factory.inflate(R.layout.doc_prof_det_add_speciality, null);
                alertDialog.setView(view);

            alertDialog.setNegativeButton("Cancel", new DialogInterface.OnClickListener() {
                public void onClick(DialogInterface dialog, int which) {
                    dialog.dismiss();
                }
            });

            alertDialog.setPositiveButton("Save", new DialogInterface.OnClickListener() {
                public void onClick(DialogInterface dialog, int which) {

                }
            });

            alertDialog.show();
        }
    });

Upvotes: 0

Views: 46

Answers (1)

Gulmuhammad Akbari
Gulmuhammad Akbari

Reputation: 2036

Try this:

alertDialog.setNegativeButton("Cancel", new DialogInterface.OnClickListener() {
                public void onClick(DialogInterface dialog, int which) {
                    dialog.dismiss();
                }
            });

            alertDialog.setPositiveButton("Save", new DialogInterface.OnClickListener() {
                public void onClick(DialogInterface dialog, int which) {

                }
            });

            alertDialog.show();


           //Grab the window of the dialog, and change the width
           WindowManager.LayoutParams lp = new WindowManager.LayoutParams();
           Window window = alertDialog.getWindow();
           lp.copyFrom(window.getAttributes());
           //This makes the dialog take up the full width
           lp.width = WindowManager.LayoutParams.MATCH_PARENT;
           lp.height = WindowManager.LayoutParams.WRAP_CONTENT;
           window.setAttributes(lp);

    }
}); 

Upvotes: 1

Related Questions