Android 加载 ProgressBarDialog 基于spinkit动画(参照SpinKit)
基于DialogFragment 不会发生 WindowLeaked 错误
dependencies {
implementation 'top.hasiy:spinkitprogressbar:1.3.0'
}
- BaseActivity
abstract class BaseActivity : AppCompatActivity(), SpinkitProgressBarDialogManager {
override var loadingIsShow: Boolean = false
override lateinit var spinkitProgressBarDialog: SpinkitProgressBarDialog
//初始化Dialog
override fun onStart() {
SpinkitProgressBarDialogConfig.instance
.messageShow(true)
// 是否显示加载文字
.spinKitColor(Color.parseColor("#a1c4fd"))
//设置spinKit显示颜色
.spinKitStatus("WanderingCubes")
// 设置加载动画
.apply()
//应用
//SpinkitProgressBarDialogConfig.reset() 恢复默认设置
super.onStart()
}
private fun showProgressBar() {
showSpinkitProgressBarDialog(supportFragmentManager)
}
fun showBaseProgressBar() {
//显示无文字 Dialog
SpinkitProgressBarDialogConfig.instance
.messageShow(false)
.spinKitColor(Color.parseColor("#a1c4fd"))
.spinKitStatus("WanderingCubes")
.apply()
spinkitProgressBarDialog =
SpinkitProgressBarDialog.instance("")
showProgressBar()
}
fun showBaseProgressBar(text: String) {
//显示文字 Dialog
SpinkitProgressBarDialogConfig.instance
.messageShow(true)
.spinKitColor(Color.parseColor("#a1c4fd"))
.spinKitStatus("WanderingCubes")
.apply()
spinkitProgressBarDialog =
SpinkitProgressBarDialog.instance(text)
showProgressBar()
}
//关闭 Dialog
fun dismissBaseProgressBar() {
if (!this.isDestroyed && !this.isFinishing) {
dismissSpinkitProgressBarDialog()
}
}
}
-
其他Activity 调用
显示 : showBaseProgressBar() || showBaseProgressBar("加载中...") 关闭 : dismissBaseProgressBar()
样式 | 预览 |
---|---|
RotatingPlane | |
DoubleBounce | |
Wave | |
WanderingCubes | |
Pulse | |
ChasingDots | |
ThreeBounce | |
Circle | |
CubeGrid | |
FadingCircle | |
FoldingCube | |
RotatingCircle | |
Heartbeat |