A Material styled AlertDialog

Are you looking for a Material styled AlertDialog?

Here a short gist to migrate the "old" AlertDialog
 AlertDialog.Builder builder = new AlertDialog.Builder(this);
        builder.setTitle("Dialog");
        builder.setMessage("Lorem ipsum dolor sit amet, consectetuer adipiscing elit. Aenean commodo ligula eget dolor. Aenean massa. Cum sociis natoque penatibus et magnis dis parturient montes, nascetur ridiculus mus. Donec quam felis, ultricies nec, pellentesque eu, pretium quis, sem. Nulla consequat massa quis enim. Donec pede justo,");
        builder.setPositiveButton("OK", null);
        builder.setNegativeButton("Cancel", null);
        builder.show();

Now you can use the new android.support.v7.app.AlertDialog and the the code becomes:

import android.support.v7.app.AlertDialog;

  AlertDialog.Builder builder = new AlertDialog.Builder(this, R.style.AppCompatAlertDialogStyle);
        builder.setTitle("Dialog");
        builder.setMessage("Lorem ipsum dolor sit amet, consectetuer adipiscing elit. Aenean commodo ligula eget dolor. Aenean massa. Cum sociis natoque penatibus et magnis dis parturient montes, nascetur ridiculus mus. Donec quam felis, ultricies nec, pellentesque eu, pretium quis, sem. Nulla consequat massa quis enim. Donec pede justo,");
        builder.setPositiveButton("OK", null);
        builder.setNegativeButton("Cancel", null);
        builder.show();
using this style:

   <style name="AppCompatAlertDialogStyle" parent="Theme.AppCompat.Light.Dialog.Alert">
        <item name="colorAccent">#FFCC00</item>
        <item name="android:textColorPrimary">#FFFFFF</item>
        <item name="android:background">#5fa3d0</item>
    </style>
and you can enjoy your material styled Dialog on Kitkat:


or on Lollipop:

If you would like tu use a custom style for the title (for example) you can use a style like this:

    <style name="AppCompatAlertDialogStyle" parent="Theme.AppCompat.Light.Dialog.Alert">
        <item name="colorAccent">#FFCC00</item>
        <item name="android:textColorPrimary">#FFFFFF</item>
        <item name="android:background">#5fa3d0</item>

        <item name="android:windowTitleStyle">@style/TitleDialogTextStyle</item>
    </style>

    <style name="TitleDialogTextStyle" parent="Base.DialogWindowTitle.AppCompat">
        <item name="android:textColor">#d71616</item>
    </style>

Comments

  1. Do you understand there is a 12 word sentence you can say to your crush... that will induce intense feelings of love and impulsive appeal for you buried within his heart?

    That's because hidden in these 12 words is a "secret signal" that fuels a man's impulse to love, idolize and care for you with his entire heart...

    ====> 12 Words Who Trigger A Man's Desire Response

    This impulse is so built-in to a man's brain that it will make him try better than before to take care of you.

    Matter-of-fact, triggering this mighty impulse is absolutely binding to having the best possible relationship with your man that the second you send your man a "Secret Signal"...

    ...You'll soon find him open his mind and soul to you in such a way he never expressed before and he'll perceive you as the one and only woman in the universe who has ever truly interested him.

    ReplyDelete

Post a Comment

Popular posts from this blog

Expand and collapse animation

NotificationListenerService and kitkat

NotificationListenerService and a Whatsapp extension for Dashclock