George
George

Reputation: 2997

Material Components Confirmation Dialog

How can I implement the horizontal dividers or the elevation which can be seen on the Title and Buttons in the dialog box in the following image?

Confirmation Dialog

I have installed the material components library and used the dialog documentation as a guide.

The code is as follows:

MaterialAlertDialogBuilder materialAlertDialogBuilder = new MaterialAlertDialogBuilder(this.getActivity());

LayoutInflater inflater = ((Activity) context).getLayoutInflater();
View view = inflater.inflate(R.layout.dialog_settings, null);

setupView(view);


materialAlertDialogBuilder.setView(view);
materialAlertDialogBuilder.setTitle("Settings");

materialAlertDialogBuilder.setPositiveButton("OK", new DialogInterface.OnClickListener()
{
    @Override
    public void onClick(DialogInterface dialog, int which)
    {

    }
});

materialAlertDialogBuilder.setNegativeButton("CANCEL", new DialogInterface.OnClickListener()
{
    @Override
    public void onClick(DialogInterface dialog, int which)
    {

    }
});

materialAlertDialogBuilder.setCancelable(false);
materialAlertDialogBuilder.create();
materialAlertDialogBuilder.show();

The MaterialAlertDialogBuilder does not seem to have the ability to set this property.

Upvotes: 4

Views: 4865

Answers (1)

Gabriele Mariotti
Gabriele Mariotti

Reputation: 364401

Just use the standard MaterialAlertDialogBuilder.
It is the default behavior if you have the title panel, the button panel and a content that requires a scrollable view.

For example:

    CharSequence[] choices = {"Choice1", "Choice2", "Choice3", "Choice1", "Choice2", "Choice3","Choice1", "Choice2", "Choice3","Choice1", "Choice2", "Choice3","Choice1", "Choice2", "Choice3","Choice1", "Choice2", "Choice3"};
    boolean[] choicesInitial = {false, true, false, false, true, false,false, true, false,false, true, false, false, true, false,false, true, false};

    new MaterialAlertDialogBuilder(MainActivity.this)
        .setTitle("Title")
        .setMultiChoiceItems(choices, choicesInitial, null)
        .setPositiveButton("ok", null)
        .setNegativeButton("Cancel", null)
        .show();

enter image description here

Using a long message, with the title and buttons you can obtain:

new MaterialAlertDialogBuilder(AlertDialogActivity.this)
            .setTitle("Title")
            .setMessage(multiLineMessage.toString())
            .setPositiveButton("ok", null)
            .setNegativeButton("Cancel", null)
            .show();

enter image description here

Upvotes: 2

Related Questions