Android Native dialog is too blunt, before seeing this effect is very good but no use, today to others recommended use, he encountered problems, import error is very much, there is no library engineering. So I took a serious look at it, this is a Androidstudio project, and it also depends on the Materialish-progress project, but also as the project. So I plan to get an Eclipse version and merge the two projects together as a library engineering xalertdialoglibrary. When used, you can import it as a library into your project.
The effect is as follows
Very simple to use, the test code is as follows:
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 ()) {case r.id.basic_test://Default Ti
Tle "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). Settitletex
T ("Are you sure?")
. Setcontenttext ("Won ' t be able to recover this file!")
. Setconfirmtext ("Yes,delete it!") . SetconfirmclicklistenER (new Sweetalertdialog.onsweetclicklistener () {@Override public void OnClick (Sweetalertdialog SD
Ialog) {//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
("Are you sure?")
. Setcontenttext ("Won ' t be able to recover this file!")
. Setcanceltext ("No,cancel plx!")
. Setconfirmtext ("Yes,delete it!") . Showcancelbutton (True). Setcancelclicklistener (New Sweetalertdialog.onsweetclicklistener () {@O Verride public void OnclicK (Sweetalertdialog Sdialog) {//Reuse previous dialog instance, keep widget user state, reset them if
Need Sdialog.settitletext ("cancelled!") . Setcontenttext ("Your imaginary file is safe:)"). Setconfirmtext ("OK"). showcance
Lbutton (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). Settitletext ("cancelled!")
. Setcontenttext ("Your imaginary file is safe:)"). Setconfirmtext ("OK") . Show (); */}). Setconfirmclicklistener (New Sweetalertdialog.onsweetclickli
Stener () { @Override public void OnClick (Sweetalertdialog sdialog) {sdialog.settitletext ("D Eleted! ").
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). Settitletex
T ("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_t
ype). 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 (). Setbarcolor (Getresources (). GetColor (R.color.
Blue_btn_bg_color));
Break
Case 1:pdialog.getprogresshelper (). Setbarcolor (Getresources (). GetColor (R.COLOR.MATERIAL_DEEP_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_deep_teal_20));
Break Case 4:pdialog.getprogresshelper (). Setbarcolor (Getresources (). getcOlor (r.color.material_blue_grey_80));
Break
Case 5:pdialog.getprogresshelper (). Setbarcolor (Getresources (). GetColor (R.color.warning_stroke_color));
Break
Case 6:pdialog.getprogresshelper (). Setbarcolor (Getresources (). GetColor (R.color.success_stroke_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= "Wra" P_content "> <imageview android:id=" @+id/logo_img "android:layout_width=" 180DP "an
droid:layout_height= "Wrap_content" android:src= "@drawable/logo_big" android:layout_margintop= "10DP" Android:layout_marginbottom= "15DP" android:layout_centerhorizontal= "true" Android:contentdescriptio n= "@string/app_name"/> <textview android:id= "@+id/txt_0" Android:layout_alignleft = "@id/logo_img" android:layout_below= "@id/logo_img" android:layout_marginleft= "15DP" a ndroid:text= "Show material progRess "android:layout_width=" wrap_content "android:layout_height=" Wrap_content "Android : textsize= "14sp" android:textcolor= "#797979"/> <button Android:layout_centerhoriz Ontal= "true" android:layout_below= "@id/txt_0" android:id= "@+id/progress_dialog" 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_ce Nterhorizontal= "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 "a" Ndroid:textsize= "14SP" android:layout_margintop= "15DP" android:textcolor= "#797979"/> ; Button android:layout_centerhorizontal= "true" android:layout_below= "@id/txt_2" Android:id = "@+id/under_text_test" style= "@style/dialog_blue_button" android:layout_margin= "10DP" an droid:text= "Try me!" /> <textview android:id= "@+id/txt_3"Android:layout_alignleft=" @id/logo_img "android:layout_below=" @id/under_text_test "Andr
oid:layout_marginleft= "15DP" android:text= "Show error message" Android:layout_width= "Wrap_content" android:layout_height= "Wrap_content" android:textsize= "14sp" android:layout_margintop= "15d"
P "android:textcolor=" #797979 "/> <button android:layout_centerhorizontal=" true " android:layout_below= "@id/txt_3" android:id= "@+id/error_text_test" style= "@style/dialog_blue_butto N "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 Me Ssage "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:layout_bel ow= "@id/txt_4" android:id= "@+id/success_text_test" style= "@style/dialog_blue_button" Android : layout_margin= "10DP" android:text= "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" android:text= "A warning Message, with a listener bind to the Confirm-button ... "android:layout_width= 200dp" android:layout_he ight= "Wrap_content" android:textsize= "14sp" android:layout_margintop= "15DP" Android:textcolo
R= "#797979"/> <button android:layout_centerhorizontal= "true" android:layout_below= "@id/txt_5" android:id= "@+id/warning_confirm_test" style= "@style/dialog_blue_b Utton "android:layout_margin=" 10DP "android:text=" Try me! " /> <textview android:id= "@+id/txt_6" android:layout_alignleft= "@id/logo_img" a ndroid:layout_below= "@id/warning_confirm_test" android:layout_marginleft= "15DP" android:text= "A warnin G message, with listeners bind to Cancel and Confirm button ... "android:layout_width= 200dp" android:l ayout_height= "Wrap_content" android:textsize= "14sp" android: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/dialog_blue_button" Android:lay Out_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_height= "wrap_content" android:textsize= "14SP" android:layout_margintop= "15DP" android:textcolor= "#797979"/> <button android:layout_cente Rhorizontal= "true" android:layout_below= "@id/txt_7" android:id= "@+id/custom_img_test" style= "@s" Tyle/dialog_blue_button "android:layout_margin=" 10DP "android:text=" Try me! "
/> </RelativeLayout> </ScrollView>
Xalertdialoglibrary (Eclipse): Click here to download
The above is the android dialog box Sweet-alert-dialog data collation, follow-up continue to supplement the relevant information, thank you for your support of this site!