0
我已經使用Android Studio的導航抽屜(模板)。根據教程,我可以在'content_main'xml中輕鬆看到進度條。然而,每當活動開始時,進度條就沒有可見的地方。我已經嘗試了很多教程,包括使用FrameLayout代替ConstraintLayout,使用線性佈局使用工具欄內的進度條。請幫助我。 'content_main'的代碼如下所示。使用應用程序時無法查看進度條(水平)。 (導航抽屜)
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
app:layout_behavior="@string/appbar_scrolling_view_behavior"
tools:context="parts.tractor.versa.com.versatractorparts.MainActivity"
tools:showIn="@layout/app_bar_main">
<ProgressBar
android:id="@+id/progressBar"
style="?android:attr/progressBarStyleHorizontal"
android:layout_width="match_parent"
android:layout_height="40dp"
android:layout_gravity="top"
android:progressDrawable="@drawable/bg_progress_bar_webview"/>
<WebView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:id="@+id/webView"/>
和Java文件如下:
webView = (WebView) findViewById(R.id.webView);
mProgressBar = (ProgressBar) findViewById(R.id.progressBar);
final Activity activity = this;
webView.setWebChromeClient(new WebChromeClient()
{
public void onProgressChanged(WebView view, int progress) {
// Activities and WebViews measure progress with different scales.
// The progress meter will automatically disappear when we reach 100%
activity.setProgress(progress * 100);
}
});
webView.setWebViewClient(new WebViewClient(){
public boolean shouldOverrideUrlLoading(WebView view, String url) {
view.loadUrl(url);
return true;
}
@Override
public void onPageStarted(WebView view, String url, Bitmap favicon) {
super.onPageStarted(view, url, favicon);
mProgressBar.setVisibility(View.VISIBLE);
}
@Override
public void onPageFinished(WebView view, String url) {
super.onPageFinished(view, url);
mProgressBar.setVisibility(View.GONE);
}
});
謝謝。但是,我一直在尋找我使用過的進度條,並想知道爲什麼它沒有顯示的確切原因。 –