0

I just started learning android development, and I want to make a dialog box that looks nice.

this is what I have right now.

This is how I want it to be.

I tried looking it up and most of them tell me to make a new shape and add it as the dialog box background, but I don't seem to understand how to set the new shape as the background.

this is my code for the dialog box:

new AlertDialog.Builder(this)
                .setTitle(" ")
                .setMessage("Congrats! Player " + winner +" wins!")
                .setPositiveButton("Play again", new DialogInterface.OnClickListener()
                {
                    @Override
                    public void onClick(DialogInterface dialog, int which) {
                        //my code here
                    }

                })
                .setNegativeButton("F", null)
                .show();

how do I link my shape background xml to this dialog and how do I make the positive button have a background like in the screenshot?

Edit: question edited because I already tried the method below I don't seem to understand it, besides it has multiple parts (header, footer) which I don't really need my requirement is much more basic.

Shashank Setty
  • 138
  • 1
  • 9
  • For that you need to create custom layout. See this: https://stackoverflow.com/questions/12501488/android-alertdialog-with-rounded-corners/21304547 – Zakaria Hossain Feb 04 '19 at 15:02

1 Answers1

1

You can easily set a custom view for your AlertDialog using setView(View view) for your dialog.

Your code would be like this:

View view = inflater.inflate(R.layout.your_layout_name, null);
new AlertDialog.Builder(this)
                .setView(view)
                .create()
                .show();