Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to Build AppCompatDialog From AlertDialog.Builder or Equivalent?

Before this I used a DialogBuilder to create AlertDialog like this

AlertDialog.Builder builder = new AlertDialog.Builder(context);
...
...
AlertDialog dialog = builder.create();

How can I build the new AppCompatDialog from a dialog builder, or is there another new equivalent way to do that?

like image 923
Neoh Avatar asked Apr 22 '15 01:04

Neoh


People also ask

Which method is used to set in AlertDialog?

Alert Dialog code has three methods:setTitle() method for displaying the Alert Dialog box Title. setMessage() method for displaying the message. setIcon() method is used to set the icon on the Alert dialog box.

What is the significance of AlertDialog builder?

Returns a Context with the appropriate theme for dialogs created by this Builder. Set a list of items, which are supplied by the given ListAdapter , to be displayed in the dialog as the content, you will be notified of the selected item via the supplied listener. Sets whether the dialog is cancelable or not.

What is the significance of AlertDialog builder in Android?

Alert Dialog shows the Alert message and gives the answer in the form of yes or no. Alert Dialog displays the message to warn you and then according to your response the next step is processed. Android Alert Dialog is built with the use of three fields: Title, Message area, Action Button.


2 Answers

Just found the solution. I should import

import android.support.v7.app.AlertDialog;

and then AppCompatDialog dialog = builder.create() will work.

like image 50
Neoh Avatar answered Sep 24 '22 23:09

Neoh


If you would like to use an AlertDialog, just import the new supprt v 22.1 and use a code like this (pay attention to the import):

import android.support.v7.app.AlertDialog

AlertDialog.Builder builder =
       new AlertDialog.Builder(this, R.style.AppCompatAlertDialogStyle);
            builder.setTitle("Dialog");
            builder.setMessage("Lorem ipsum dolor ....");
            builder.setPositiveButton("OK", null);
            builder.setNegativeButton("Cancel", null);
            builder.show();

If

like image 30
Gabriele Mariotti Avatar answered Sep 21 '22 23:09

Gabriele Mariotti