【发布时间】:2019-02-26 06:58:24
【问题描述】:
如果用户点击这种类型的链接,我想打开 Play 商店:market://
我尝试使用 getUrl(),但它仅在第一次获取 URL,而不是当用户点击 webView 中的其他链接时。
这是我的代码:
swipeLayout = (SwipeRefreshLayout) findViewById(R.id.swipeLayout);
swipeLayout.setOnRefreshListener(this);
progressBar = (ProgressBar) findViewById(R.id.progressBar);
progressBar.setMax(100);
webview = (WebView) findViewById(R.id.dashboard);
webview.getSettings().setJavaScriptEnabled(true);
webview.setScrollBarStyle(View.SCROLLBARS_INSIDE_OVERLAY);
webview.loadUrl("http://example.test");
webview.setWebViewClient(new WebViewClient());
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) {
webview.setLayerType(View.LAYER_TYPE_HARDWARE, null);
} else {
webview.setLayerType(View.LAYER_TYPE_SOFTWARE, null);
}
progressBar.setProgress(0);
webview.setWebChromeClient(new WebChromeClient());
webview.setWebChromeClient(new WebChromeClient() {
public void onProgressChanged(WebView view, int progress) {
progressBar.setProgress(progress);
if (progress == 100) {
progressBar.setVisibility(View.GONE);
} else {
progressBar.setVisibility(View.VISIBLE);
}
super.onProgressChanged(view, progress);
}
});
【问题讨论】:
-
使用您自己的
WebViewClient自定义子类,在其中覆盖shouldOverrideUrlLoading()并注意该 URL。
标签: java android webview webchromeclient