试图TabHost打开的WebView [英] Trying to open WebView in TabHost

查看:215
本文介绍了试图TabHost打开的WebView的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

行,所以我想创建一个小的应用程序打开在3个不同的选项卡3个不同的网页视图。目前,我有我的tabhost创建OK和我的WebView一个单独的类,但是当我打开应用程序不显示。

Ok so i'm trying to create a small app that opens 3 different webviews within 3 different tabs. At the moment I Have my tabhost created ok and a separate class for my webview but when I open the app it doesn't display.

Tabhost code

Tabhost code

public class HelloTabWidgetActivity extends TabActivity {
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.main);

    Resources res = getResources(); // Resource object to get Drawables
    TabHost tabHost = getTabHost();  // The activity TabHost
    TabHost.TabSpec spec;  // Resusable TabSpec for each tab
    Intent intent;  // Reusable Intent for each tab

    // Create an Intent to launch an Activity for the tab (to be reused)
    intent = new Intent().setClass(this, HelloWebViewActivity.class);

    // Initialize a TabSpec for each tab and add it to the TabHost
    spec = tabHost.newTabSpec("albums").setIndicator("News",
            res.getDrawable(R.drawable.ic_tab_albums))
        .setContent(intent);
    tabHost.addTab(spec);

    // Do the same for the other tabs
    intent = new Intent().setClass(this, SongsActivity.class);
    spec = tabHost.newTabSpec("songs").setIndicator("SaintsTV",
                      res.getDrawable(R.drawable.ic_tab_songs))
                  .setContent(intent);
    tabHost.addTab(spec);

    intent = new Intent().setClass(this, ArtistsActivity.class);
    spec = tabHost.newTabSpec("artists").setIndicator("Fixtures",
                      res.getDrawable(R.drawable.ic_tab_artists))
                  .setContent(intent);
    tabHost.addTab(spec);

    tabHost.setCurrentTab(0);
}

}

的WebView code

webview code

public class HelloWebViewActivity extends Activity {
    WebView mWebView;
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.main);

        mWebView = (WebView) findViewById(R.id.webview);
        mWebView.getSettings().setJavaScriptEnabled(true);
        mWebView.loadUrl("http://www.google.com");
        mWebView.setWebViewClient(new HelloWebViewClient());
    }
}

我不明白一个问题,我已经阅读了有关TabHostContentFactory其他国家人民的职位,但我不知道如何使应用程序打开时加载web视图。任何帮助将不胜收。

I can't see a problem and I have read other peoples posts regarding TabHostContentFactory but I have no idea how to make it load the webview when the app opens. Any help would be greatly received.

以上code是基于HelloWebView教程和HelloTabWidget教程

The above code is based on the HelloWebView tutorial and the HelloTabWidget tutorial

推荐答案

我试过同样的事情,有时回来,后来想通了,我没有为应用程序申报appropraite上网权限。这是原因,web视图中的tabhost是越来越空白,有一个在logcat中没有错误或者

I had tried the same things sometime back and later figured out that I did not declare appropraite Internet access permissions for the app. That was the reason, webview in the tabhost was getting blank and there was no error in the Logcat either.

<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />

添加上述行的Andr​​oidManifest.xml中已经解决了我的问题。

Adding above lines to the AndroidManifest.xml had resolved my problem.

这篇关于试图TabHost打开的WebView的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆