我的问题非常简单,我有一个打开“mywebsite.com”的webview,但在我的网站上有一些广告和弹出窗口,所以我想要webview加载我的网址并阻止其他像弹出窗口...等等 这是我的webview代码:
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
customViewContainer = (FrameLayout) findViewById(R.id.customViewContainer);
webView = (VideoEnabledWebView) findViewById(R.id.webView);
// mWebViewClient = new myWebViewClient();
// webView.setWebViewClient(mWebViewClient);
mWebChromeClient = new myWebChromeClient();
webView.setWebChromeClient(mWebChromeClient);
//webView.getSettings().setPluginState(WebSettings.PluginState.OFF);
webView.getSettings().setAllowFileAccess(false);
webView.getSettings().setJavaScriptCanOpenWindowsAutomatically(false);
webView.getSettings().setJavaScriptEnabled(true);
webView.getSettings().setAppCacheEnabled(true);
webView.getSettings().setBuiltInZoomControls(false);
webView.getSettings().setSaveFormData(false);
webView.loadUrl("http://aflamzone.com");
webView.setWebViewClient(new WebViewClient());
WebSettings settings = webView.getSettings();
settings.setSupportMultipleWindows(false);
请帮帮我,我需要一个解决方案,谢谢大家。
答案 0 :(得分:0)
您可以执行以下操作:
webView.setWebViewClient(new WebViewClient() {
@Override
public boolean shouldOverrideUrlLoading(final WebView view, final String url) {
if (url.equals("http://aflamzone.com")) {
return false;
}
return true;
}
@RequiresApi(api = Build.VERSION_CODES.LOLLIPOP)
@Override
public boolean shouldOverrideUrlLoading(final WebView view, final WebResourceRequest request) {
if (request.getUrl().toString().equals("http://aflamzone.com")) {
return false;
}
return true;
}
});