在窗体上放了一个WebView显示某个网页,为什么真机上会调用浏览器打开?
WebView mWebView=(WebView) findViewById(R.id.webView1);
mWebView.loadUrl("http://www.yuneach.com");
在模拟器上,这个网页是在我自己的Activity上显示的,但是我把应用安装到手机上时,却弹出选择浏览器,然后是浏览器中显示了网页(脱离了我的Activity),请问这个怎么回事?
[解决办法]
你的是默认使用的是手机自带的浏览器打开
看下面这个↓
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
// get the view web intent
Intent intent = this.getViewWebIntent();
this.printInterestedActivitiesByIntent(intent);
// set the className to use the specific browser to open the webpage.
intent.setClassName("com.tencent.mtt", "com.tencent.mtt.MainActivity");
startActivity(intent);
}
/*
*get the desired view web intent
*/
private Intent getViewWebIntent() {
Intent viewWebIntent = new Intent(Intent.ACTION_VIEW);
Uri uri = Uri.parse("http://www.2cto.com");
viewWebIntent.setData(uri);
return viewWebIntent;
}
[解决办法]
2楼的是直接调用系统的显示页面的吧!
[解决办法]
mWebView1 是自己定义的webView控件,加个方法就行。url是你的初始地址,之后每次点击都是在你的Activity中跳转而不会打开浏览器
mWebView1.setWebViewClient(new WebViewClient() { @Override public boolean shouldOverrideUrlLoading(WebView view, String url) { view.loadUrl(url); // 在当前的webview中跳转到新的url return true; } });
[解决办法]
Android系统防止browser新开链接,必须覆盖WebView的WebViewClient对象!