我正在尝试设置一个进度微调器(在andorid中)以便在webview加载后消失,但是根本无法使用它,微调器使用onPageStarted但不会消失使用onPageFinished有没有人知道我是什么我做错了吗?
public class MainActivity extends AppCompatActivity {
private WebView mWebView;
private ProgressBar spinner;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
mWebView = (WebView) findViewById(R.id.activity_main_webview);
spinner = (ProgressBar)findViewById(R.id.progressBar1);
//spinner.setVisibility(WebView.VISIBLE);
// Enable Setup Webview
// WebView myWebView = (WebView) findViewById(R.id.myWebView);
mWebView.loadUrl("https://google.com");
// myWebView.setWebViewClient(new MyWebViewClient());
mWebView.setWebViewClient(new WebViewClient() {
public void onPageStarted(WebView view, String url) {
spinner.setVisibility(WebView.VISIBLE);
}
public void onPageFinished(WebView view, String url) {
// do your stuff here
spinner.setVisibility(WebView.GONE);
}
});
// Enable Javascript
WebSettings webSettings = mWebView.getSettings();
webSettings.setJavaScriptEnabled(true);
// Force links and redirects to open in the WebView instead of in a browser
mWebView.setWebViewClient(new WebViewClient());
}
答案 0 :(得分:1)
你正在覆盖旧的webViewClient。
//删除此项,因为您已在上面设置了一个负责显示和隐藏进度条的内容。
mWebView.setWebViewClient(new WebViewClient());