一、简介
MaterialAlertDialogBuilder 是官方material设计库中的弹框组件,下面简单的介绍一下其使用。
二、添加依赖
添加依赖:
implementation 'com.google.android.material:material:1.1.0-alpha07'
要使用这个组件,需要将activity的主题设为:
Theme.MaterialComponents.*
这个或者其下的别的子类型,当然也可以在你创建MaterialAlertDialogBuilder的时候传入主题
MaterialAlertDialogBuilder(this,R.style.Theme_MaterialComponents)
三、使用
使用方式和以前的AlertDialog是一样的,如下:
MaterialAlertDialogBuilder(this)
.setTitle("MaterialDialog")
.setMessage("这个是测试MaterialAlertDialog的测试Demo")
.setNegativeButton("确定", null)
.setPositiveButton("取消", null)
.show()
效果如下: