gpt4 book ai didi

java - 如何使屏幕变暗并在android中启动progressBar?

转载 作者:行者123 更新时间:2023-11-29 03:32:04 25 4
gpt4 key购买 nike

我正在写一个 android 应用程序,我想当 httpclient.execute() 被执行时,屏幕变暗并出现一个进度条,直到这一行被执行,我该怎么办?我的代码是这样的:

ProgressBar x = (ProgressBar) findViewById("R.id.progress") ;
x.setVisibility(ProgressBar.VISIBLE) ;
httpclient.execute()
x.setVisibility(ProgressBar.GONE) ;

但是使用这段代码只会出现进度条,屏幕不会变暗。

最佳答案

首先,我建议您在异步类中完成所有网络。您可以使用以下模板将您的代码放入异步类中。将 ProgressDialog 作为类变量。

YouClass
{
ProgressDialog dialog;

onCreate(....)
{
//Execute the async task here.
new myNetworkingTask().execute("");
}

private class myNetworkingTask extends AsyncTask<String, Void, String> {

@Override
protected String doInBackground(String... params)
{
//In this method you will do the networking task
httpclient.execute();
}
return "";
}

@Override
protected void onPostExecute(String result) {
//In this method you will hide the progress bar
dialog.dismiss();
}

@Override
protected void onPreExecute() {
//In this method you will display the progress bar.
dialog = ProgressDialog.show(MyActivity.this, "",
"Loading. Please wait...", true);
}

@Override
protected void onProgressUpdate(Void... values) {
}

关于java - 如何使屏幕变暗并在android中启动progressBar?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17675728/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com