1. 首先在app的build.gradle中添加依赖
    compile 'com.github.f0ris.sweetalert:library:1.5.1'

  2. 这个时候同步一下项目会报一个错误,解决办法

    1. 在AndroidManifest.xml中manifest根标签添加
      xmlns:tools="http://schemas.android.com/tools"
    2. 在application标签下添加
      tools:replace="android:icon,android:theme,android:allowBackup"
  3. 使用代码

    1
    2
    3
    4
    5
    SweetAlertDialog pDialog = new SweetAlertDialog(this, SweetAlertDialog.PROGRESS_TYPE);
    pDialog.getProgressHelper().setBarColor(Color.parseColor("#A5DC86"));
    pDialog.setTitleText("Loading");
    pDialog.setCancelable(false);
    pDialog.show();
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
//你可以通过SweetAlertDialog.getProgressHelper()调用materialish-progress中下面这些方法,来动态改变进度条的样式

resetCount()
isSpinning()
spin()
stopSpinning()
getProgress()
setProgress(float progress)
setInstantProgress(float progress)
getCircleRadius()
setCircleRadius(int circleRadius)
getBarWidth()
setBarWidth(int barWidth)
getBarColor()
setBarColor(int barColor)
getRimWidth()
setRimWidth(int rimWidth)
getRimColor()
setRimColor(int rimColor)
getSpinSpeed()
setSpinSpeed(float spinSpeed)

//只显示标题:

new SweetAlertDialog(this)
.setTitleText("Here's a message!")
.show();

//显示标题和内容:

new SweetAlertDialog(this)
.setTitleText("Here's a message!")
.setContentText("It's pretty, isn't it?")
.show();

//显示异常样式:

new SweetAlertDialog(this, SweetAlertDialog.ERROR_TYPE)
.setTitleText("Oops...")
.setContentText("Something went wrong!")
.show();

//显示警告样式:

new SweetAlertDialog(this, SweetAlertDialog.WARNING_TYPE)
.setTitleText("Are you sure?")
.setContentText("Won't be able to recover this file!")
.setConfirmText("Yes,delete it!")
.show();

//显示成功完成样式:

new SweetAlertDialog(this, SweetAlertDialog.SUCCESS_TYPE)
.setTitleText("Good job!")
.setContentText("You clicked the button!")
.show();

//自定义头部图像:

new SweetAlertDialog(this, SweetAlertDialog.CUSTOM_IMAGE_TYPE)
.setTitleText("Sweet!")
.setContentText("Here's a custom image.")
.setCustomImage(R.drawable.custom_img)
.show();

//确认事件绑定:

new SweetAlertDialog(this, SweetAlertDialog.WARNING_TYPE)
.setTitleText("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 sDialog) {
sDialog.dismissWithAnimation();
}
})
.show();

//显示取消按钮及事件绑定:

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() {
@Override
public void onClick(SweetAlertDialog sDialog) {
sDialog.cancel();
}
})
.show();

//确认后切换对话框样式:

new SweetAlertDialog(this, SweetAlertDialog.WARNING_TYPE)
.setTitleText("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 sDialog) {
sDialog
.setTitleText("Deleted!")
.setContentText("Your imaginary file has been deleted!")
.setConfirmText("OK")
.setConfirmClickListener(null)
.changeAlertType(SweetAlertDialog.SUCCESS_TYPE);
}
})
.show();

参考:https://blog.csdn.net/taa1007/article/details/79551928