由JavaScript启发SweetAlert安卓对话框
截图
建立
使用SweetAlertDialog最简单的方法是将图书馆作为AAR依赖添加到您的构建。
Maven的
cn.pedant.sweetalert
library
1.3
aar
摇篮
repositories {
mavenCentral()
}
dependencies {
compile 'cn.pedant.sweetalert:library:1.3'
}
用法
秀物质文明
SweetAlertDialog pDialog = new SweetAlertDialog(this, SweetAlertDialog.PROGRESS_TYPE);
pDialog.getProgressHelper().setBarColor(Color.parseColor("#A5DC86"));
pDialog.setTitleText("Loading");
pDialog.setCancelable(false);
pDialog.show();
您可以动态地定制进度条通过materialish正在进行的方法SweetAlertDialog.getProgressHelper():
resetCount()
isSpinning()
旋()
stopSpinning()
getProgress()
setProgress(浮点进度)
setInstantProgress(浮点进度)
getCircleRadius()
setCircleRadius(INT circleRadius)
getBarWidth()
setBarWidth(INT barWidth)
getBarColor()
setBarColor(INT barColor)
getRimWidth()
setRimWidth(INT rimWidth)
getRimColor()
setRimColor(INT rimColor)
getSpinSpeed()
setSpinSpeed(浮动spinSpeed)
由于该项目materialish正在进行和@croccio参与。
更多用途有关进度,请参阅样本。
基本信息:
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();
A错误信息:
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();