Sean Hill Sean Hill - 2 months ago 6
Android Question

If I make my own DialogFragment do I have to make my own buttons?

I notice that if I use a regular DialogFragment I can have the OK/Cancel buttons built into it.

But if I want to replace the body of the DialogFragment with something custom, I can't have the OK/Cancel buttons built-in; I have to add them myself.

But if I add them myself, now it's no longer the same formatting as the original.

Is there a way to recreate the same buttons as the built-ins?

Answer

Hey I'm using this library for material dialogs and its really great. So back to your question and this library: if you will use custom view you can keep buttons as well as create own. It's up to you to decide. This is example:

   MaterialDialog dialog = new MaterialDialog.Builder(this)
            .title(R.string.googleWifi)
            .customView(R.layout.dialog_customview, true)
            .positiveText(R.string.connect)
            .negativeText(android.R.string.cancel)
            .onPositive(new MaterialDialog.SingleButtonCallback() {
                @Override
                public void onClick(@NonNull MaterialDialog dialog, @NonNull DialogAction which) {
                    showToast("Password: " + passwordInput.getText().toString());
                }
            }).build();