点击网页视图打开手机浏览器 [英] WebView clicks opens mobile browser
问题描述
有一个的WebView
它加载移动优化URL(网页)。但是,当我点击一个链接,它不会在的WebView
里面加载(里面的应用程序),但手机浏览器中打开。
如何prevent呢?
我试图通过 shouldOverrideUrlLoading()
超载的网址,但它并没有帮助。
这是一个code。
web视图=(的WebView)findViewById(R.id.webview);
WebSettings webSettings = webView.getSettings();
webSettings.setPluginsEnabled(真);
如果(Build.VERSION.SDK_INT大于7){
webSettings.setPluginState(WebSettings.PluginState.ON);
}
webSettings.setJavaScriptEnabled(真);
webView.setWebViewClient(新WebViewClient(){
@覆盖
公共布尔shouldOverrideUrlLoading(的WebView视图,字符串URL){
如果(url.equals(URL)){
view.loadUrl(URL);
返回true;
}
返回false;
}
@覆盖
公共无效onLoadResource(的WebView视图,字符串URL){
}
});
webView.loadUrl(http://some-url.com);
修改
确实 GET
或 POST
发布方法与链接点击打开手机网页浏览器??? <什么/ p>
返回真正
而不是假
在 shouldOverrideUrlLoading
。
从文档:
shouldOverrideUrlLoading如果主机应用程序要返回True
离开当前的WebView和处理URL本身,否则返回
假的。
块引用>There is a
WebView
which loads mobile-optimized URL (webpage). But when I click on a link, it does not load inside of theWebView
(inside of the app), but mobile browser opens.How to prevent this?
I tried overloading URLs via
shouldOverrideUrlLoading()
, but it did not help.This is a code.
webView = (WebView) findViewById(R.id.webview); WebSettings webSettings = webView.getSettings(); webSettings.setPluginsEnabled(true); if (Build.VERSION.SDK_INT > 7) { webSettings.setPluginState(WebSettings.PluginState.ON); } webSettings.setJavaScriptEnabled(true); webView.setWebViewClient(new WebViewClient() { @Override public boolean shouldOverrideUrlLoading(WebView view, String url) { if (url.equals(url)) { view.loadUrl(url); return true; } return false; } @Override public void onLoadResource(WebView view, String url) { } }); webView.loadUrl("http://some-url.com");
EDIT
Does
GET
orPOST
posting methods have anything with links' clicks open mobile web browser???解决方案Return
true
instead offalse
inshouldOverrideUrlLoading
.From the documentation:
shouldOverrideUrlLoading returns True if the host application wants to leave the current WebView and handle the url itself, otherwise return false.
这篇关于点击网页视图打开手机浏览器的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!