我試圖使用有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控制它嗎? –
是的,你可以。試試吧 –