更新时间:2023-11-18 23:52:58
您必须创建一个 WebViewClient
:
公共类myWebViewClient扩展WebViewClient {
@覆盖
公共布尔shouldOverrideUrlLoading(web视图查看,字符串URL){
view.loadUrl(URL);
返回true;
}
}
然后将其设置为你的的WebView
是这样的:
webview.setWebViewClient(新myWebViewClient());
I have a webview in my android app, but when someone navigates around the site, it opens in a new window, i want it to stay inside the webview.. is there a way to do this easily? Here is the code in my activity:
super.onCreate(savedInstanceState);
setContentView(R.layout.shop);
WebView webview;
webview = (WebView) findViewById(R.id.webview);
webview.getSettings().setJavaScriptEnabled(true);
webview.loadUrl("http://www.google.co.uk");
You'll have to create a WebViewClient
:
public class myWebViewClient extends WebViewClient {
@Override
public boolean shouldOverrideUrlLoading(WebView view, String url) {
view.loadUrl(url);
return true;
}
}
And then set it to your WebView
like this:
webview.setWebViewClient(new myWebViewClient());