Material AlertDialog using AppCompat v22.1.0

Material AlertDialog has become easier to implement using latest version of AppCompat v22.1.0. It has come up with a awesome solution to make use of Material AlertDialog in pre Lollipop devices without using any third party library integration. In order to use it so please update your sdk.

Now let us see the step by step implementation of Material AlertDialog.

STEP 1:

Update your AppCompat version from 21 or whatever to v22.1.0.

STEP 2:

Apply following style codes in styles.xml.

STEP 3:

Use below code in your MainActivity or wherever you need AlertDialog in your Application.

AlertDialog.Builder builder = new AlertDialog.Builder(this, R.style.AppCompatAlertDialogStyle);
builder.setTitle("Dialog");
builder.setMessage("Hello here is the best example of AppCompatAlertDialog
from www.takeoffandroid.com. Lets make use of it");
builder.setPositiveButton("OK", null);
builder.setNegativeButton("Cancel", null);
builder.show();

STEP 4:

Last but not least!. You have to import android.support.v7.app.AlertDialog rather importing import android.app.AlertDialog.

Happy coding!!