ユーザーがのリンクをクリックしたときwebview
。ユーザーがデフォルトのブラウザで表示するかどうかを尋ねるダイアログを表示したいのですが、[はい]を選択した場合はデフォルトのブラウザに移動する必要があり、そうでない場合はリンクがまったく読み込まれません。
しかし、私が直面している問題は、オーバーライドされたメソッドの内部run()
にダイアログを表示できることです。ユーザーが「はい」を選択すると、デフォルトのブラウザーに表示するようになります。ただし、ユーザーがYES / NOを選択したかどうかに関係なく、回避したいリンクが表示されます。どんな提案もありがたい...TIAWebViewClient's
shouldOverrideUrlLoading()
startActivity(new Intent(Intent.ACTION_VIEW,Uri.parse(url)));
webview
質問する
1410 次
2 に答える
1
WebView myWebView = (WebView) findViewById(R.id.webview);
myWebView.setWebViewClient(new WebViewClient());
private class MyWebViewClient extends WebViewClient {
@Override
public boolean shouldOverrideUrlLoading(WebView view, String url) {
if (Uri.parse(url).getHost().equals("www.example.com")) {
// This is my web site, so do not override; let my WebView load the page
return false;
}
// Otherwise, the link is not for a page on my site, so launch another Activity that handles URLs
Intent intent = new Intent(Intent.ACTION_VIEW, Uri.parse(url));
startActivity(intent);
return true;
}
}
于 2012-11-27T06:47:58.793 に答える
0
shouldOverrideUrlLoading()メソッド内で同じURLをリロードするだけで、問題を解決しました。あなたの提案をありがとう
于 2012-11-27T07:02:50.877 に答える