1

I need some help for my dialog issue. I created dialogFragment from custom view and set positive/negative buttons like this:

  @Override
public Dialog onCreateDialog(Bundle savedInstanceState) {
    AlertDialog.Builder builder = new AlertDialog.Builder(getActivity());
    LayoutInflater inflater = getActivity().getLayoutInflater();
    builder.setView(inflater.inflate(R.layout.add_product, null)).
            setPositiveButton(R.string.add, new DialogListener(getActivity(), true)).
            setNegativeButton(R.string.cancel, new DialogListener(getActivity(), false));
    return builder.create();
}

An what I've got: enter image description here Here is the question: how can I get buttons like shown in sample: enter image description here

I like that style of button much more, how can I use it in this case.

Rahul
  • 1,332
  • 1
  • 9
  • 24
Bitlejuce Do
  • 65
  • 1
  • 11
  • 2
    You need to add buttons in your custom layout for this. – Lucifer Mar 12 '18 at 11:13
  • I think you should go with custom alertdialog. By custom alertdialog i mean that you can make xml layout file as you wish and then simply apply `dialog.setView(R.layout.your_custom_layout)`. – Jaydip Kalkani Mar 12 '18 at 11:14
  • create two button in `R.layout.add_product` file and add `setOnClickListner` in code. – KuLdip PaTel Mar 12 '18 at 11:15
  • @Lucifer I might be wrong here but I think his question was more towards obtaining the specific style of buttons rather than setting up a custom dialog (as he is already setting a fragment as his dialog instead of using the default one) – Karan Shishoo Mar 12 '18 at 11:22
  • @casualcoder, but to have the buttons as he mentioned, he must need to add button in custom layout. This is the only way it is possible. – Lucifer Mar 12 '18 at 11:23
  • @Lucifer i agree with that. My interpretation was that he may have been asking for better xml as the default android buttons are bulky and don't mesh well in alertdialogs. – Karan Shishoo Mar 12 '18 at 11:26
  • Thanks for your answers, I realized that ways. According to material design that type of buttons are correct https://material.io/guidelines/components/dialogs.html?hl=ru# So, let it be – Bitlejuce Do Mar 12 '18 at 11:36

1 Answers1

-1
builder.setPositiveButton("Sighin", new DialogInterface.OnClickListener() {
    public void onClick(DialogInterface dialog, int id) {
        dialog.dismiss();
    }
});

builder.setNegativeButton("Cancel", new DialogInterface.OnClickListener() {
    public void onClick(DialogInterface dialog, int id) {
        dialog.dismiss();
    }
});
AlertDialog alertDialog = builder.create();
alertDialog.show();
break;
André Kool
  • 4,418
  • 12
  • 31
  • 43
bugfreerammohan
  • 1,443
  • 1
  • 5
  • 18