TabHost 单击时启动外部浏览器
我的应用程序中有一些选项卡,我希望最后一个选项卡在默认系统浏览器中启动谷歌。我认为这会起作用:
Uri uri = Uri.parse("http://www.google.com/");
tabHost.addTab(tabHost.newTabSpec("tab3").setIndicator("Google", res.getDrawable(R.drawable.google)).setContent(new Intent(Intent.ACTION_VIEW, uri)));
但它会导致强制关闭错误。有什么建议可以让它发挥作用吗?
编辑 我解决了这个问题。基本上我所做的是添加一个 onClick 事件处理程序来捕获何时单击该选项卡(仅此选项卡),然后在启动新 Intent 后通过返回 true(用于处理)来阻止默认操作以常规方式。
I have some tabs in my app and I want the last tab to launch google in the default system browser. I thought this would work:
Uri uri = Uri.parse("http://www.google.com/");
tabHost.addTab(tabHost.newTabSpec("tab3").setIndicator("Google", res.getDrawable(R.drawable.google)).setContent(new Intent(Intent.ACTION_VIEW, uri)));
But it results in a force close error. Any tips on getting this working?
EDIT
I solved this. Basically what I do is add an onClick event handler to capture when the tab is clicked in the first place (only this tab in question) and then from within that I prevent the default action by returning true (for handled) after launching a new Intent in the regular fashion.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您可以从选项卡主机启动一个活动(您在最后一个选项卡主机中提到过)。然后从该活动您可以启动外部浏览器。因为我认为不可能从选项卡主机启动默认活动。
已编辑
我已经检查过了。它给出了 ActivityNotFound 异常。结论是 TabHost 会查找在 Android 清单中注册的活动。如果您想实现它,请按照我的第一个建议
You can start an Activity from Tab Host(that you have mention as last Tab Host).Then from that activity you can launch external Browser.As i think its not possible to launch default activity from TabHost.
Edited
I have checked it.It give ActivityNotFound Exception.Conclusion is that TabHost look for the activity that is registered in Android manifest.If you want to achieve it then go with my first suggestion