android原生的dialog太生硬了,看到开源的sweet-alert-dialog 对话框感觉不错 ,我根据个人的需要基于sweet-alert-dialog做了一些修改 自我感觉挺好看 大家需要的话 可以下下来研究下 有源码 用eclipse的同学 拿去改一下应该也可以用
下载地址:https://download.csdn.net/download/wl200881/10647910
效果如下
更多样式再次就不一一展示了,需要的朋友可以下载来研究下
下载地址:https://download.csdn.net/download/wl200881/10647910
代码片段如下:
@Override
public void onClick(View v) {
switch (v.getId()) {
case R.id.only_title: // 只有标题
MyAlertDialog dd = new MyAlertDialog(this) ;
dd.setTitleText("您还未登录,请先登录") ;
dd.show();
break;
case R.id.basic_test: //可点空白处取消对话框
// default title "Here's a message!"
MyAlertDialog sd = new MyAlertDialog(this);
sd.setContentText("点击空白处可取消对话框");
sd.setCancelable(true);
sd.setCanceledOnTouchOutside(true);
sd.show();
break;
case R.id.under_text_test: // 只有内容
new MyAlertDialog(this)
.setContentText("您还未登录,请先登录")
.show();
break;
case R.id.text_test: // 有标题和内容
new MyAlertDialog(this)
.setTitleText("友情提示")
.setContentText("您还未登录,请先登录")
.show();
break;
case R.id.error_text_test: // 报错提示 多一个错误的图标
new MyAlertDialog(this, MyAlertDialog.ERROR_TYPE)
.setTitleText("友情提示")
.setContentText("网络未连接,请检查网络")
.show();
break;
case R.id.success_text_test:// 成功提示 多一个成功的图标
new MyAlertDialog(this, MyAlertDialog.SUCCESS_TYPE)
.setTitleText("友情提示")
.setContentText("用户名修改成功")
.show();
break;
case R.id.warning_confirm_sure: // 警告事件 多了一个警告图标 点击后消失
new MyAlertDialog(this, MyAlertDialog.WARNING_TYPE_1)
.setTitleText("是否要删除?")
.setContentText("删除后会影响部分功能")
.setConfirmText("是的,删除")
.setConfirmClickListener(new MyAlertDialog.OnSweetClickListener() {
@Override
public void onClick(MyAlertDialog sDialog) {
// reuse previous dialog instance
sDialog.dismissWithAnimation();
}
})
.show();
break;
case R.id.warning_confirm_test: //警告事件 多了一个警告图标 点击后显示删除成功
new MyAlertDialog(this, MyAlertDialog.WARNING_TYPE_1)
.setTitleText("是否要删除?")
.setContentText("删除后会影响部分功能")
.setConfirmText("是的,删除")
.setConfirmClickListener(new MyAlertDialog.OnSweetClickListener() {
@Override
public void onClick(MyAlertDialog sDialog) {
// reuse previous dialog instance
sDialog.setTitleText("删除成功")
.setContentText("文件删除成功")
.setConfirmText("确定")
.setConfirmClickListener(null)
.changeAlertType(MyAlertDialog.SUCCESS_TYPE);
}
})
.show();
break;
case R.id.warning_cancel_test: //警告事件 有两个选项 多了一个警告图标 没有图标
new MyAlertDialog(this, MyAlertDialog.WARNING_TYPE)
.setTitleText("确定删除?")
.setContentText("删除后影响部分功能")
.setCancelText("取消")
.setConfirmText("确定")
.showCancelButton(true)
.setCancelClickListener(new MyAlertDialog.OnSweetClickListener() {
@Override
public void onClick(MyAlertDialog sDialog) {
// reuse previous dialog instance, keep widget user state, reset them if you need
sDialog.setTitleText("已取消")
.setContentText("文件删除取消")
.setConfirmText("确定")
.showCancelButton(false)
.setCancelClickListener(null)
.setConfirmClickListener(null)
.changeAlertType(MyAlertDialog.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 MyAlertDialog.OnSweetClickListener() {
@Override
public void onClick(MyAlertDialog sDialog) {
sDialog.setTitleText("已删除")
.setContentText("文件已删除")
.setConfirmText("确定")
.showCancelButton(false)
.setCancelClickListener(null)
.setConfirmClickListener(null)
.changeAlertType(MyAlertDialog.SUCCESS_TYPE);
}
})
.show();
break;
case R.id.warning_cancel_test_1: //警告事件 有两个选项 多了一个警告图标 图标颜色默认
new MyAlertDialog(this, MyAlertDialog.WARNING_TYPE_1)
.setTitleText("确定删除?")
.setContentText("删除后影响部分功能")
.setCancelText("取消")
.setConfirmText("确定")
.showCancelButton(true)
.setCancelClickListener(new MyAlertDialog.OnSweetClickListener() {
@Override
public void onClick(MyAlertDialog sDialog) {
// reuse previous dialog instance, keep widget user state, reset them if you need
sDialog.setTitleText("已取消")
.setContentText("文件删除取消")
.setConfirmText("确定")
.showCancelButton(false)
.setCancelClickListener(null)
.setConfirmClickListener(null)
.changeAlertType(MyAlertDialog.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 MyAlertDialog.OnSweetClickListener() {
@Override
public void onClick(MyAlertDialog sDialog) {
sDialog.setTitleText("已删除")
.setContentText("文件已删除")
.setConfirmText("确定")
.showCancelButton(false)
.setCancelClickListener(null)
.setConfirmClickListener(null)
.changeAlertType(MyAlertDialog.SUCCESS_TYPE);
}
})
.show();
break;
case R.id.warning_cancel_test_2: //警告事件 有两个选项 多了一个警告图标 第二个图标颜色红色
new MyAlertDialog(this, MyAlertDialog.WARNING_TYPE_2)
.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 MyAlertDialog.OnSweetClickListener() {
@Override
public void onClick(MyAlertDialog 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(MyAlertDialog.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 MyAlertDialog.OnSweetClickListener() {
@Override
public void onClick(MyAlertDialog sDialog) {
sDialog.setTitleText("Deleted!")
.setContentText("Your imaginary file has been deleted!")
.setConfirmText("OK")
.showCancelButton(false)
.setCancelClickListener(null)
.setConfirmClickListener(null)
.changeAlertType(MyAlertDialog.SUCCESS_TYPE);
}
})
.show();
break;
case R.id.custom_img_test: // 显示一个头像
new MyAlertDialog(this, MyAlertDialog.CUSTOM_IMAGE_TYPE)
.setTitleText("千城智联")
.setContentText("千城聚力 智慧互联")
.setCustomImage(R.drawable.ic_launcher_background)
.show();
break;
case R.id.progress_dialog: // 显示加载loading
final MyAlertDialog pDialog = new MyAlertDialog(this, MyAlertDialog.PROGRESS_TYPE)
.setTitleText("Loading");
pDialog.show();
pDialog.setCancelable(false);
new CountDownTimer(800 * 7, 800) {
public void onTick(long millisUntilFinished) {
// you can change the progress bar color by ProgressHelper every 800 millis
i++;
switch (i){
case 0:
pDialog.getProgressHelper().setBarColor(getResources().getColor(R.color.m_blue_btn_bg_color));
break;
case 1:
pDialog.getProgressHelper().setBarColor(getResources().getColor(R.color.m_material_deep_teal_50));
break;
case 2:
pDialog.getProgressHelper().setBarColor(getResources().getColor(R.color.m_success_stroke_color));
break;
case 3:
pDialog.getProgressHelper().setBarColor(getResources().getColor(R.color.m_material_deep_teal_20));
break;
case 4:
pDialog.getProgressHelper().setBarColor(getResources().getColor(R.color.m_material_blue_grey_80));
break;
case 5:
pDialog.getProgressHelper().setBarColor(getResources().getColor(R.color.m_warning_stroke_color));
break;
case 6:
pDialog.getProgressHelper().setBarColor(getResources().getColor(R.color.m_success_stroke_color));
break;
}
}
public void onFinish() {
i = -1;
pDialog.setTitleText("Success!")
.setConfirmText("OK")
.changeAlertType(MyAlertDialog.SUCCESS_TYPE);
}
}.start();
break;
}