我想要做的是使我的TabWidget中的Tabs指向一个webview,而不是所有三个人都有一个单独的web视图。Android:Tabwidget(三个标签)与一个webview(不是所有的单独webviews)
我到目前为止所做的基本上是采取此Tab-Layout-tutorial并在不同的选项卡中创建webviews。这工作正常。
问题是,这显然同时打开三个网站。这不是我想要完成的。我想要的是,所有三个标签链接到一个webview。
我找了一个答案,但不幸找不到一个。我发现有人在SO here上做了完全相同的事情,但不幸的是我不太明白如何自己做。
目前我的应用程序与教程中的应用程序非常相似,除了在选项卡(而不是textviews)中有三个独立的Web视图之外,就像这样(完全相同,除了名称,次3):
public class SongsActivity extends Activity {
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.webview);
WebView webView = (WebView) findViewById(R.id.myWebView);
webView.getSettings().setJavaScriptEnabled(true);
webView.setWebViewClient(new WebViewClient());
webView.loadUrl("http://www.google.com");
}
}
class MyWebViewClient extends WebViewClient {
@Override
public boolean shouldOverrideUrlLoading(WebView view, String url) {
boolean result = false;
/* ... */
// Return false to proceed loading page, true to interrupt loading
return result;
}
}
我再有main.xml中布局文件:
android:id="@android:id/tabhost"
android:layout_width="fill_parent"
android:layout_height="fill_parent">
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:padding="5dp">
android:id="@android:id/tabs"
android:layout_width="fill_parent"
android:layout_height="wrap_content" />
android:id="@android:id/tabcontent"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:padding="5dp" />
和webview.xml布局文件:
xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/myWebView"
android:layout_width="fill_parent"
android:layout_height="fill_parent" />
我AndroidManifest.xml中:
package="hellotabwidget.android"
android:versionCode="1"
android:versionName="1.0" >
android:icon="@drawable/ic_launcher"
android:label="@string/app_name" >
android:name=".HelloTabWidgetActivity"
android:label="@string/app_name" android:theme="@android:style/Theme.NoTitleBar">
+0
@Emile ..如果要使用单个webview从选项卡加载不同/或同一网站,然后创建三个选项卡和一个acti与Webview vity和获得webview的实例,并在OnClick事件方法中传递网址,试试这个..仍然有任何麻烦让我知道我会张贴示例代码 –
+0
谢谢你!我希望明天能够继续工作,但在2天内另行报告。再次感谢你 –