SpotsDialog – 平滑流畅的进度Dialog
从API26开始,Android支持库中的ProgressDialog就被标记为Deprecated,也就是弃用状态。如果要寻找一种替代方案,则需要在App的UI里嵌入ProgressBar ,不过这有时候会很麻烦。这种时候使用第三方库是一个不错的选择。
SpotsDialog正是这样的一个库,效果图如下:
有点类似巨硬Office的启动界面,对吧?
在Gradle中添加依赖:
repositories { jcenter() } dependencies { implementation 'com.github.d-max:spots-dialog:1.1@aar' }
使用:
AlertDialog spotsDialog = new SpotsDialog.Builder() .setContext(this) .setMessage(R.string.please_wait) .setCancelable(false) .setTheme(R.style.MySpotsDialog) .build(); spotsDialog.show(); new Thread(() -> { //TODO: 在此处处理耗时任务 spotsDialog.dismiss(); }).start();
Style可在XML中自定义:
<?xml version="1.0" encoding="utf-8"?> <resources> <style name="MySpotsDialog" parent="android:Theme.DeviceDefault.Dialog"> <item name="DialogTitleAppearance">@android:style/TextAppearance.Medium</item> <item name="DialogTitleText">Updating…</item> <item name="DialogSpotColor">@android:color/holo_orange_dark</item> <item name="DialogSpotCount">4</item> </style> </resources>
项目地址: https://github.com/d-max/spots-dialog
该项目基于MIT协议开源。
One Response
Hello. This article was extremely remarkable, especially since I was searching for thoughts on this issue last Tuesday. Brandon Fliger