显示加载/进度指示器的最佳方式?
问题描述:
在应用等待服务器响应时显示加载微调器的最佳方式是什么?
What is the best way to show a loading spinner while the app is waiting for a response from the server?
这可以以编程方式完成吗?这样我就不必在 xml 文件中添加加载微调器了?
Can this be done programmatically? So that I don't have to add the load spinner in the xml file?
答
ProgressDialog 已从 Android Oreo 中弃用.改用 ProgressBar
ProgressDialog is deprecated from Android Oreo. Use ProgressBar instead
ProgressDialog progress = new ProgressDialog(this);
progress.setTitle("Loading");
progress.setMessage("Wait while loading...");
progress.setCancelable(false); // disable dismiss by tapping outside of the dialog
progress.show();
// To dismiss the dialog
progress.dismiss();
或
ProgressDialog.show(this, "Loading", "Wait while loading...");
顺便说一下,Spinner 在 Android 中有不同的含义.(就像 HTML 中的选择下拉菜单)
By the way, Spinner has a different meaning in Android. (It's like the select dropdown in HTML)