jvargas
jvargas

Reputation: 843

How to create popup form on Android Studio?

What I am trying to do is show a customer form which will have edittext fields for the user to type. I intend the form to be some sort of a pop up screen and have the back screen a black fade out. I access this form at the push of a button. I do not want it to be like another activity screen.

I am asking for guidance not the solution. Any help or suggestions on what to look for to take this approach would be great, thanks!

Upvotes: 0

Views: 878

Answers (1)

Mervin Hemaraju
Mervin Hemaraju

Reputation: 2127

Use the AlertDialog or MaterialAlertDialog

A sample code for you:

final AlertDialog dialogBuilder = new AlertDialog.Builder(this).create();
    LayoutInflater inflater = this.getLayoutInflater();
    View dialogView = inflater.inflate(R.layout.custom_dialog, null);

    final EditText editText = (EditText) dialogView.findViewById(R.id.edt_comment);
    Button button1 = (Button) dialogView.findViewById(R.id.buttonSubmit);
    Button button2 = (Button) dialogView.findViewById(R.id.buttonCancel);

    button2.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View view) {
            dialogBuilder.dismiss();
        }
    });
    button1.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View view) {
            // DO SOMETHINGS
            dialogBuilder.dismiss();
        }
    });

    dialogBuilder.setView(dialogView);
    dialogBuilder.show();

Upvotes: 2

Related Questions