我无法停止一个ProgressBar
,它的样式是ProgressBarStylesmall
。如何开始和停止一个圆形、小的ProgressBar
?
我无法停止一个ProgressBar
,它的样式是ProgressBarStylesmall
。如何开始和停止一个圆形、小的ProgressBar
?
默认情况下,您可以按以下方式使progressBar可见并在不需要时隐藏它:
progressBar.setVisibility(View.GONE);
如果你想通过编程来控制它,那么可以使用以下方式实现:
progressBar.setVisibility(View.VISIBLE); //to show
progressBar.setVisibility(View.GONE); // to hide
你甚至可以使用ProgressDialog:
private ProgressDialog progressDialog;
...
public void showProgressDialog() {
if (progressDialog == null) {
progressDialog = new ProgressDialog(PhotographerDetailActivity.this);
progressDialog.setIndeterminate(true);
progressDialog.setCancelable(false);
}
progressDialog.setMessage("your message");
progressDialog.show();
}
public void dismissProgressDialog() {
if (progressDialog != null ) {
progressDialog.dismiss();
}
希望它能够对你有所帮助。
您需要处理AsyncTasks。
/*
* We set the visibility to true. If it was already visible
* there's no need of doing this but we do it for the sake of readability.
*/
final ProgressBar progressBar = (ProgressBar)findViewById(R.id.progressBar1);
progressBar.setVisibility(View.VISIBLE);
new AsyncTask<Void,Void,Void>(){
//The variables you need to set go here
@Override
protected Void doInBackground(final Void... params){
// Do your loading here. Don't touch any views from here, and then return null
return null;
}
@Override
protected void onPostExecute(final Void result){
// Update your views here
progressBar.setVisibility(View.GONE);
}
}.execute()
隐藏进度条: progressBar.setVisibility(View.INVISIBLE);
显示进度条: progressBar.setVisibility(View.VISIBLE);
关于GONE和INVISIBLE的区别,可以在这里阅读。
我不知道这是否有帮助,但你可以使用一个 ProgressDialog
。假设你有一个正在运行的名为 progressDialog
的 ProgressDialog
,你可以使用 progressDialog.dismiss();
。只需确保你要解除显示的 ProgressDialog
实例是实际显示的 ProgressDialog
。你可以使用 progressDialog.isShowing();
来检查它。要启动 ProgressDialog
:
progressDialog = ProgressDialog
.show(myActivityContext,
"ProgressDialog Title",
"ProgressDialog Body");
ProgressDialog
的用户界面是圆形的,就像您需要的那样。 style="?android:attr/progressBarStyleHorizontal"
android:indeterminate="false"
任务开始时将setAlpha值设置为1,任务完成后将其改回0, 但setAlpha仅适用于API级别11或更高版本