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?
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.
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.
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.
Just found the solution. I should import
import android.support.v7.app.AlertDialog;
and then AppCompatDialog dialog = builder.create()
will work.
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
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With