网站/小程序/APP个性化定制开发,二开,改版等服务,加扣:8582-36016

可在Android应用中使用的材料警报对话框

应用介绍

作者TutorialsAndroid,源码KAlertDialog,AlertDialog for Android,一个美丽的材料警报对话框,可在Android应用中使用。

屏幕截图

注意

新版本的15.4.19 requireAPINew版本不支持旧的Android版本。


建立

使用AlertDialog的最简单方法是将库添加为构建的依赖项。

完整

将其添加到存储库末尾的根build.gradle中:

allprojects {
    repositories {
        ...
        maven { url 'https://jitpack.io' }
    }
}

添加依赖项:

dependencies {
        implementation 'com.github.TutorialsAndroid:KAlertDialog:v15.4.19'
}

使用

显示材料进度

KAlertDialog pDialog = new KAlertDialog(this, KAlertDialog.PROGRESS_TYPE);
pDialog.getProgressHelper().setBarColor(Color.parseColor("#A5DC86"));
pDialog.setTitleText("Loading");
pDialog.setCancelable(false);
pDialog.show();

您可以使用物质进度方法通过KAlertDialog.getProgressHelper动态自定义进度条:

  • 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 KAlertDialog(this)
    .setTitleText("Here's a message!")
    .show();

带有文字的标题:

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

错误信息:

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

警告信息:

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

成功信息:

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

带有自定义图标的消息:

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

绑定监听器确认按钮:

new KAlertDialog(this, KAlertDialog.WARNING_TYPE)
    .setTitleText("Are you sure?")
    .setContentText("Won't be able to recover this file!")
    .setConfirmText("Yes,delete it!")
    .setConfirmClickListener(new KAlertDialog.KAlertClickListener() {
        @Override
        public void onClick(KAlertDialog sDialog) {
            sDialog.dismissWithAnimation();
        }
    })
    .show();

显示取消按钮并将监听器绑定到它:

new KAlertDialog(this, KAlertDialog.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 KAlertDialog.KAlertClickListener() {
        @Override
        public void onClick(KAlertDialog sDialog) {
            sDialog.cancel();
        }
    })
    .show();

自定义警报对话框:

.confirmButtonColor(R.color.colorPrimary) // you can change the color of confirm button
.cancelButtonColor(R.color.colorAccent) // you can change the color of cancel button

如果想用颜色更改按钮角,创建一个可绘制文件:

    
                                                                                                                                                        

然后在创建drawable时调用此方法:

  .confirmButtonColor(R.drawable.button_background) // you can change border and color of button

如果要隐藏警告对话框的标题文本和内容文本:

.setTitleText("Are you sure?") //just don't write this line if you want to hide title text
.setContentText("Won't be able to recover this file!") // don't write this line if you want to hide content text

确认后更改对话框样式:

new KAlertDialog(this, KAlertDialog.WARNING_TYPE)
    .setTitleText("Are you sure?")
    .setContentText("Won't be able to recover this file!")
    .setConfirmText("Yes,delete it!")
    .setConfirmClickListener(new KAlertDialog.KAlertClickListener() {
        @Override
        public void onClick(KAlertDialog sDialog) {
            sDialog
                .setTitleText("Deleted!")
                .setContentText("Your imaginary file has been deleted!")
                .setConfirmText("OK")
                .setConfirmClickListener(null)
                .changeAlertType(KAlertDialog.SUCCESS_TYPE);
        }
    })
    .show();

立即下载

请到会员中心签到后即可获得免费下载!

评论 共有 0 条评论

暂无评论
0
0
0
立即
投稿
发表
评论
返回
顶部