我试图使用有4个选项卡的tabhost内的WebView - 所有链接到同一网页视图。网页视图中TabHost =开始为黑屏
这是除了一个问题很大: 在启动web视图是黑色的。 单击标签2,3或4使它“活着”。
我的快速解决方案是使用setCurrentTab(1),然后回到0,但这看起来很丑,所以我想我可能会问一个解决方案,因为我找不到任何东西在线。
这怎么解决?下面是我的XML:
<?xml version="1.0" encoding="utf-8"?>
<TabHost xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@android:id/tabhost"
android:layout_width="fill_parent"
android:layout_height="fill_parent">
<LinearLayout
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent">
<FrameLayout
android:id="@android:id/tabcontent"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layout_weight="1">
<android.webkit.WebView android:layout_width="fill_parent" android:id="@+id/webview" android:layout_height="fill_parent" android:scrollbars="none"/>
</FrameLayout>
<TabWidget
android:id="@android:id/tabs"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_weight="0"
/>
</LinearLayout>
</TabHost>
更新: 把web视图外的FrameLayout会导致应用程序在启动时出现以下错误崩溃: 了java.lang.RuntimeException:无法创建选项卡的内容,因为不能鉴于找到ID为2131099648
这发生在我的onCreate方法初始化我tabhost这样的:通过
mTabHost = getTabHost();
mTabHost.addTab(mTabHost.newTabSpec("tab_test1").setIndicator("Tab1", getResources().getDrawable(R.drawable.ligenu)).setContent(R.id.webview));
mTabHost.addTab(mTabHost.newTabSpec("tab_test2").setIndicator("Tab2", getResources().getDrawable(R.drawable.mad)).setContent(R.id.webview));
mTabHost.addTab(mTabHost.newTabSpec("tab_test3").setIndicator("Tab3", getResources().getDrawable(R.drawable.godpris)).setContent(R.id.webview));
mTabHost.addTab(mTabHost.newTabSpec("tab_test4").setIndicator("Tab4", getResources().getDrawable(R.drawable.om)).setContent(R.id.webview));
将其从“FrameLayout”中移除。将它添加为'LinearLayout'的子项 –
这仍然让我通过我的tabhost控制它吗? –
是的,你可以。试试吧 –