无法在 webview 中打开默认网页
我是android开发新手, 我有一个带有网络视图的应用程序。该网络视图位于我的选项卡布局的框架布局内。我的选项卡正常显示网页,但我的默认选项卡显示空白屏幕。这是我已实现的代码。请帮我解决这个问题。
private WebView webview;
private TabHost mTabHost;
public class HelloWebViewClient extends WebViewClient {
@Override
public boolean shouldOverrideUrlLoading(WebView view, String url) {
view.loadUrl(url);
return true;
}
}
public void onCreate(Bundle icicle) {
super.onCreate(icicle);
setContentView(R.layout.main);
mTabHost = getTabHost();
mTabHost.addTab(mTabHost.newTabSpec("tab_featured").setIndicator("Featured", getResources().getDrawable(R.drawable.featured_selected)).setContent(R.id.webview));
mTabHost.addTab(mTabHost.newTabSpec("tab_recent").setIndicator("recent", getResources().getDrawable(R.drawable.recent_selected)).setContent(R.id.webview));
mTabHost.addTab(mTabHost.newTabSpec("tab_playlist").setIndicator("playlist", getResources().getDrawable(R.drawable.playlist_selected)).setContent(R.id.webview));
mTabHost.addTab(mTabHost.newTabSpec("tab_search").setIndicator("search", getResources().getDrawable(R.drawable.search_selected)).setContent(R.id.webview));
mTabHost.setCurrentTab(0);
webview = (WebView) findViewById(R.id.webview);
webview.loadUrl("http://www.google.com");
webview.setWebViewClient(new HelloWebViewClient());
webview.getSettings().setJavaScriptEnabled(true);
webview.getSettings().setPluginsEnabled(true);
webview.getSettings().setAllowFileAccess(true);
mTabHost.setOnTabChangedListener(new OnTabChangeListener() {
@Override
public void onTabChanged(String tabId) {
if(tabId.equals("tab_featured")){
webview.loadUrl("http://www.facebook.com");
}else if(tabId.equals("tab_recent")){
webview.loadUrl("http://www.useit.com");
}else if(tabId.equals("tab_playlist")){
webview.loadUrl("http://www.flipkart.com");
}else if(tabId.equals("tab_search")){
webview.loadUrl("http://www.hotmail.com");
}
}
} );
提前致谢 :)
I am new to android development,
I have an application with a webview. This webview is inside my tablayout's framelayout. My tabs are showing up webpages proerly but but my default tab is displaying a blank screen. Here is my code which is implemented. Please help me to fix this problem.
private WebView webview;
private TabHost mTabHost;
public class HelloWebViewClient extends WebViewClient {
@Override
public boolean shouldOverrideUrlLoading(WebView view, String url) {
view.loadUrl(url);
return true;
}
}
public void onCreate(Bundle icicle) {
super.onCreate(icicle);
setContentView(R.layout.main);
mTabHost = getTabHost();
mTabHost.addTab(mTabHost.newTabSpec("tab_featured").setIndicator("Featured", getResources().getDrawable(R.drawable.featured_selected)).setContent(R.id.webview));
mTabHost.addTab(mTabHost.newTabSpec("tab_recent").setIndicator("recent", getResources().getDrawable(R.drawable.recent_selected)).setContent(R.id.webview));
mTabHost.addTab(mTabHost.newTabSpec("tab_playlist").setIndicator("playlist", getResources().getDrawable(R.drawable.playlist_selected)).setContent(R.id.webview));
mTabHost.addTab(mTabHost.newTabSpec("tab_search").setIndicator("search", getResources().getDrawable(R.drawable.search_selected)).setContent(R.id.webview));
mTabHost.setCurrentTab(0);
webview = (WebView) findViewById(R.id.webview);
webview.loadUrl("http://www.google.com");
webview.setWebViewClient(new HelloWebViewClient());
webview.getSettings().setJavaScriptEnabled(true);
webview.getSettings().setPluginsEnabled(true);
webview.getSettings().setAllowFileAccess(true);
mTabHost.setOnTabChangedListener(new OnTabChangeListener() {
@Override
public void onTabChanged(String tabId) {
if(tabId.equals("tab_featured")){
webview.loadUrl("http://www.facebook.com");
}else if(tabId.equals("tab_recent")){
webview.loadUrl("http://www.useit.com");
}else if(tabId.equals("tab_playlist")){
webview.loadUrl("http://www.flipkart.com");
}else if(tabId.equals("tab_search")){
webview.loadUrl("http://www.hotmail.com");
}
}
} );
Thanks in advance :)
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
移到
该行之后
Move
after this line