我发现ProgressDialog现在已经被弃用了。除了ProgressBar,还有什么替代工具可以代替它。 我使用的是android studio 2.3.3版。
ProgressDialog progressDialog=new ProgressDialog(this);
progressDialog.show();
我发现ProgressDialog现在已经被弃用了。除了ProgressBar,还有什么替代工具可以代替它。 我使用的是android studio 2.3.3版。
ProgressDialog progressDialog=new ProgressDialog(this);
progressDialog.show();
当前回答
它可能对其他人有帮助。
许多流行的应用程序都有不同的方法来显示任何事情的进展,如网络请求,文件加载等。加载旋转器不会显示已加载或剩余的内容有多少。从UI/UX的角度来看,有一段时间的不确定性是不好的。许多流行的应用程序(Facebook, Linkedin等)通过首先显示基本的UI显示来解决这个问题。然后加载的内容逐渐填充在屏幕上。
我已经在我的应用程序中使用了shimmer来解决这个问题。
有一篇关于这方面的好文章,它将对其他人有益
其他回答
下面是@Han建议的ProgressDialog类的kotlin版本
class ProgressDialog(context: Context) : Dialog(context) {
init {
val view = View.inflate(context, R.layout.progress_dialog, null)
setContentView(view)
setCancelable(false)
window?.setBackgroundDrawable(
ColorDrawable(Color.TRANSPARENT)
)
}
}
ProgressBar是ProgressDialog的最佳选择。 指示操作进度的用户界面元素。
欲了解更多信息,请参阅谷歌文档:https://developer.android.com/reference/android/widget/ProgressBar.html
我使用来自https://github.com/Q115/DelayedProgressDialog的DelayedProgressDialog,它与ProgressDialog相同,在必要时具有延迟的额外好处。
使用它类似于Android O之前的ProgressDialog:
DelayedProgressDialog progressDialog = new DelayedProgressDialog();
progressDialog.show(getSupportFragmentManager(), "tag");
ProgressBar非常简单易用, 我打算制作一个同样简单的进度对话框。 第一步是你可以为你想要显示的对话框创建XML布局,假设我们命名这个布局
layout_loading_dialog.xml
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal"
android:padding="20dp">
<ProgressBar
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1" />
<TextView
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight="4"
android:gravity="center"
android:text="Please wait! This may take a moment." />
</LinearLayout>
下一步是创建AlertDialog,它将用ProgressBar显示这个布局
AlertDialog.Builder builder = new AlertDialog.Builder(context);
builder.setCancelable(false); // if you want user to wait for some process to finish,
builder.setView(R.layout.layout_loading_dialog);
AlertDialog dialog = builder.create();
现在剩下的就是在点击事件中显示和隐藏这个对话框 像这样
dialog.show(); // to show this dialog
dialog.dismiss(); // to hide this dialog
这就是它,它应该工作,因为你可以看到它是相当简单和容易实现的ProgressBar而不是ProgressDialog。 现在你可以在Handler或ASyncTask中显示/取消这个对话框,这取决于你的需要
你可以使用wasabeef库来使用SpotDialog,你可以从下面的链接找到完整的教程:
Android中的SpotsDialog示例