Android 如何有效地显示进度条?
在我的XML中,我有这个进度条,但在下载结束后,它会旋转。如何将这个进度条与我的下载代码连接起来Android 如何有效地显示进度条?,android,progress-bar,android-download-manager,Android,Progress Bar,Android Download Manager,在我的XML中,我有这个进度条,但在下载结束后,它会旋转。如何将这个进度条与我的下载代码连接起来 <ProgressBar android:id="@+id/progress_bar" android:layout_width="wrap_content" android:layout_height="wrap_content" style="@android:style/Widget.ProgressBar.Large" android:la
<ProgressBar
android:id="@+id/progress_bar"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
style="@android:style/Widget.ProgressBar.Large"
android:layout_alignParentTop="true"
android:layout_toLeftOf="@+id/button"
android:layout_toStartOf="@+id/button"
android:layout_marginTop="153dp" />
如果我想显示如下图所示的下载百分比,也可以使用进度条查看此You need ProgressDialog with AsyncTask:查看此You need ProgressDialog with AsyncTask:
downloadManager = (DownloadManager) getSystemService(Context.DOWNLOAD_SERVICE);
Uri uri = Uri.parse(downloadFileUrl);
DownloadManager.Request request = new DownloadManager.Request(uri);
nameOfFile = URLUtil.guessFileName(urlChar, null,
MimeTypeMap.getFileExtensionFromUrl(urlChar));
Log.e("url char", urlChar);
request.setDestinationInExternalPublicDir(Environment.DIRECTORY_DOWNLOADS, nameOfFile);
request.setVisibleInDownloadsUi(true);
myDownloadReference = downloadManager.enqueue(request);
getProgressPercentaged();
}