Android Beautiful dialog box item Sweet-alert-dialog

Source: Internet
Author: User

Beautiful dialog box Sweet-alert-dialog

Project Address: Https://github.com/pedant/sweet-alert-dialog

Android Native dialog too blunt, previously saw this effect is very good but not practical, today to others recommended use, he encountered problems, many errors after import, there is no library project. So I took a serious look, this is a Androidstudio project. It also relies on materialish-progressproject and is a as project. So I'm going to get an Eclipse version number and merge the two project together as a library projectxalertdialoglibrary.

You can use it as a library when you import it into your project.

Effects such as the following

watermark/2/text/ahr0cdovl2jsb2cuy3nkbi5uzxqvy2f1y2h5d2vpzxjzdhjhc3m=/font/5a6l5l2t/fontsize/400/fill/ I0jbqkfcma==/dissolve/70/gravity/center ">

watermark/2/text/ahr0cdovl2jsb2cuy3nkbi5uzxqvy2f1y2h5d2vpzxjzdhjhc3m=/font/5a6l5l2t/fontsize/400/fill/ I0jbqkfcma==/dissolve/70/gravity/center ">

easy to use, test code such as the following:

Mainactivity.java

public class Mainactivity extends Activity implements View.onclicklistener {private int i =-1;        @Override public void OnCreate (Bundle savedinstancestate) {super.oncreate (savedinstancestate);        Setcontentview (R.layout.activity_main);        Findviewbyid (r.id.basic_test). Setonclicklistener (this);        Findviewbyid (r.id.under_text_test). Setonclicklistener (this);        Findviewbyid (r.id.error_text_test). Setonclicklistener (this);        Findviewbyid (r.id.success_text_test). Setonclicklistener (this);        Findviewbyid (r.id.warning_confirm_test). Setonclicklistener (this);        Findviewbyid (r.id.warning_cancel_test). Setonclicklistener (this);        Findviewbyid (r.id.custom_img_test). Setonclicklistener (this);    Findviewbyid (R.id.progress_dialog). Setonclicklistener (this);                } @Override public void OnClick (View v) {switch (V.getid ()) {r.id.basic_test:                Default title "Here's a message!" SweetalertdialoG SD = new Sweetalertdialog (this);                Sd.setcancelable (TRUE);                Sd.setcanceledontouchoutside (TRUE);                Sd.show ();            Break Case R.id.under_text_test:new Sweetalertdialog (this). Setcontenttext ("It ' s Pretty, Isn ' t it?).                Show ();            Break Case R.id.error_text_test:new Sweetalertdialog (this, sweetalertdialog.error_type). Settitletext ("Oops ..."). Setcontenttext ("Something went wrong!").                Show ();            Break                        Case R.id.success_text_test:new Sweetalertdialog (this, sweetalertdialog.success_type)                        . Settitletext ("Good job!")                        . Setcontenttext ("You clicked the button!")                . Show ();            Break Case R.id.warning_confirm_test:new SweetaleRtdialog (this, sweetalertdialog.warning_type). Settitletext ("Is you sure?")                        . Setcontenttext ("Won ' t be able-recover this file!")                        . Setconfirmtext ("Yes,delete it!")                        . Setconfirmclicklistener (New Sweetalertdialog.onsweetclicklistener () {@Override                            public void OnClick (Sweetalertdialog sdialog) {//Reuse previous Dialog instance                                    Sdialog.settitletext ("deleted!")                                    . Setcontenttext ("Your imaginary file has been deleted!")                                    . Setconfirmtext ("OK"). Setconfirmclicklistener (NULL)                        . Changealerttype (Sweetalertdialog.success_type);                }}). Show ();            Break Case R.id.warning_cancel_test:               New Sweetalertdialog (this, sweetalertdialog.warning_type). Settitletext ("Is You Sur E? ").                        Setcontenttext ("Won ' t be able-recover this file!")                        . Setcanceltext ("No,cancel plx!")                        . Setconfirmtext ("Yes,delete it!")                            . Showcancelbutton (True). Setcancelclicklistener (New Sweetalertdialog.onsweetclicklistener () {                                @Override public void OnClick (Sweetalertdialog sdialog) {                                Reuse previous dialog instance, keep widget user state, reset them if you need                                        Sdialog.settitletext ("cancelled!")                                        . Setcontenttext ("Your imaginary file is safe:)"). Setconfirmtext ("OK")                                      . Showcancelbutton (False)  . Setcancelclicklistener (NULL). Setconfirmclicklistener (NULL)                                . Changealerttype (Sweetalertdialog.error_type);                                Or you can new a sweetalertdialog to show/* Sdialog.dismiss (); New Sweetalertdialog (Sampleactivity.this, sweetalertdialog.error_type). Sett                                        Itletext ("cancelled!")                                        . Setcontenttext ("Your imaginary file is safe:)"). Setconfirmtext ("OK") . Show (); */}}). setc                            Onfirmclicklistener (New Sweetalertdialog.onsweetclicklistener () {@Override public void OnClick (Sweetalertdialog sdialog) {sdialog.settitletext ("DEleted! ").                                        Setcontenttext ("Your imaginary file has been deleted!")                                        . Setconfirmtext ("OK"). Showcancelbutton (False)                                        . Setcancelclicklistener (NULL). Setconfirmclicklistener (NULL)                            . Changealerttype (Sweetalertdialog.success_type);                }}). Show ();            Break                        Case R.id.custom_img_test:new Sweetalertdialog (this, sweetalertdialog.custom_image_type)                        . Settitletext ("sweet!")                        . Setcontenttext ("Here's a custom image.")                . Setcustomimage (R.DRAWABLE.CUSTOM_IMG). Show ();            Break Case r.id.progress_dialog:final Sweetalertdialog pdialog = new Sweetalertdialog (this, sweetalertdialog.progress_type). Settitletext ("Loading");                Pdialog.show ();                Pdialog.setcancelable (FALSE);                        New Countdowntimer (7, +) {public void OnTick (long millisuntilfinished) {                        You can change the progress bar color by progresshelper every Millis i++; switch (i) {case 0:pdialog.getprogresshelper (). Setbarco                                Lor (Getresources (). GetColor (R.color.blue_btn_bg_color));                            Break Case 1:pdialog.getprogresshelper (). Setbarcolor (Getresources (). GetColor (R.color.material_de                                EP_TEAL_50));                            Break Case 2:pdialog.getprogresshelper (). Setbarcolor (Getresources (). GetColor (R.color.succeSs_stroke_color));                            Break Case 3:pdialog.getprogresshelper (). Setbarcolor (Getresources (). GetColor (R.color.material_de                                EP_TEAL_20));                            Break Case 4:pdialog.getprogresshelper (). Setbarcolor (Getresources (). GetColor (R.COLOR.MATERIAL_BL                                UE_GREY_80));                            Break Case 5:pdialog.getprogresshelper (). Setbarcolor (Getresources (). GetColor (R.color.warning_str                                Oke_color));                            Break Case 6:pdialog.getprogresshelper (). Setbarcolor (Getresources (). GetColor (R.color.success_str                                Oke_color));                        Break                     }} public void OnFinish () {i =-1;   Pdialog.settitletext ("success!")                    . Setconfirmtext ("OK"). Changealerttype (Sweetalertdialog.success_type);                }}.start ();        Break }    }}

Activity_main.xml

<?xml version= "1.0" encoding= "Utf-8"?

><scrollview android:layout_width= "match_parent" android:layout_height= "Match_parent" Android: Background= "#FFF" xmlns:android= "http://schemas.android.com/apk/res/android" > <relativelayout android: Layout_width= "Match_parent" android:paddingbottom= "10DP" android:layout_height= "Wrap_c Ontent "> <imageview android:id=" @+id/logo_img "android:layout_width=" 180DP " android:layout_height= "Wrap_content" android:src= "@drawable/logo_big" Android:layout_ margintop= "10DP" android:layout_marginbottom= "15DP" android:layout_centerhorizontal= "true" android:contentdescription= "@string/app_name"/> <textview android:id= "@+id/txt_0" android:layout_alignleft= "@id/logo_img" android:layout_below= "@id/logo_img" Android:layout_mar ginleft= "15DP" Android:text= "Show material Progress" android:layout_width= "Wrap_content" android:layout_height= "W Rap_content "android:textsize=" 14sp "android:textcolor=" #797979 "/> <button A Ndroid:layout_centerhorizontal= "true" android:layout_below= "@id/txt_0" android:id= "@+id/progress_dia Log "style=" @style/dialog_blue_button "android:layout_margin=" 10DP "android:text=" Try me! "/> <textview android:id=" @+id/txt_1 "android:layout_alignleft=" @id/logo_img " android:layout_below= "@id/progress_dialog" android:layout_marginleft= "15DP" android:text= "A basic Message "android:layout_width=" Wrap_content "android:layout_height=" Wrap_content "Android : textsize= "14sp" android:textcolor= "#797979"/> <button android:layout_centerhorizontal= "True" Android:layout_below= "@id/txt_1" android:id= "@+id/basic_test" style= "@style/dialog_blue_button" Android:layout_margin= "10DP" android:text= "Try me!" /> <textview android:id= "@+id/txt_2" android:layout_alignleft= "@id/logo_img" android:layout_below= "@id/basic_test" android:layout_marginleft= "15DP" Android: Text= "a title with a text under" Android:layout_width= "Wrap_content" android:layout_height= " Wrap_content "android:textsize=" 14sp "android:layout_margintop=" 15DP "Android : textcolor= "#797979"/> <button android:layout_centerhorizontal= "true" android:l ayout_below= "@id/txt_2" android:id= "@+id/under_text_test" style= "@style/dialog_blue_button" Android:layout_margin= "10DP" android:text= "Try me!" /&Gt <textview android:id= "@+id/txt_3" android:layout_alignleft= "@id/logo_img" android:layout_below= "@id/under_text_test" android:layout_marginleft= "15DP" android:text= "sh OW error message "android:layout_width=" Wrap_content "android:layout_height=" Wrap_content " Android:textsize= "14SP" android:layout_margintop= "15DP" android:textcolor= "#79 7979 "/> <button android:layout_centerhorizontal=" true "android:layout_below=" @i D/txt_3 "android:id=" @+id/error_text_test "style=" @style/dialog_blue_button " Android:layout_margin= "10DP" android:text= "Try me!" /> <textview android:id= "@+id/txt_4" android:layout_alignleft= "@id/logo_img" android:layout_below= "@id/error_text_test" android:layout_marginleft= "15DP" android:text= "A success Message" Android:layout_width= "WR Ap_content "android:layout_height=" wrap_content "android:textsize=" 14sp "Android oid:layout_margintop= "15DP" android:textcolor= "#797979"/> <button android:layou T_centerhorizontal= "true" android:layout_below= "@id/txt_4" android:id= "@+id/success_text_tes T "style=" @style/dialog_blue_button "android:layout_margin=" 10DP "Android:tex t= "Try me!" /> <textview android:id= "@+id/txt_5" android:layout_alignleft= "@id/logo_img" android:layout_below= "@id/success_text_test" android:layout_marginleft= "15DP" a ndroid:text= "A warning message, with A listener bind to the Confirm-button ..." android:layout_width= "200DP" android:layout_height= "Wrap_content" android:textsize= "14sp" android:layout_margintop= "15 DP "android:textcolor=" #797979 "/> <button android:layout_centerhorizontal=" true "Android:layout_below=" @id/txt_5 "android:id=" @+id/warning_confirm_test "sty le= "@style/dialog_blue_button" android:layout_margin= "10DP" android:text= "Try me!" /> <textview android:id= "@+id/txt_6" android:layout_alignleft= "@id/logo_img" android:layout_below= "@id/warning_confirm_test" android:layout_marginleft= "15DP" android:text= "A warning message, with listeners bind to Cancel and Confirm button ..." Android:layout_widt H= "200DP" android:layout_height= "wrap_content" android:textsize= "14SP" Androi d:layout_margintop= "15DP" Android:textcolor= "#797979"/> <button android:layout_centerhorizontal= "true" android:layout_below= "@id/txt_6" android:id= "@+id/warning_cancel_test" style= "@style/di Alog_blue_button "android:layout_margin=" 10DP "android:text=" Try me! " /> <textview android:id= "@+id/txt_7" android:layout_alignleft= "@id/logo_img" android:layout_below= "@id/warning_cancel_test" android:layout_marginleft= "15DP" android:text= "a message with a custom icon" android:layout_width= "200DP" Android:layout_hei ght= "Wrap_content" android:textsize= "14sp" android:layout_margintop= "15DP" an Droid:textcolor= "#797979"/> <button android:layout_centerhorizontal= "true" Android oid:layout_below= "@id/txt_7" andRoid:id= "@+id/custom_img_test" style= "@style/dialog_blue_button" android:layout_margin= "10DP "Android:text=" Try me! " /> </RelativeLayout></ScrollView>


xalertdialoglibrary (Eclipse): Click here to download


Android Beautiful dialog box item Sweet-alert-dialog

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.