本文介绍了在网页视图= TabHost作为启动黑屏的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图使用有4个选项卡的tabhost内的WebView - 所有链接到同一个网页视图

这是除了一个大问题:
在开始菜单上的WebView是黑色的。
点击标签2,3或4使其活了过来。

我的速战速决是使用setCurrentTab(1),然后回到0,但这个相貌丑陋,所以我想我还不如问一个解决方案,我不能在网上找到任何东西。

这怎么能解决吗?下面是我的XML:

 <?XML版本=1.0编码=UTF-8&GT?;
< TabHost的xmlns:机器人=htt​​p://schemas.android.com/apk/res/android
机器人:ID =@机器人:ID / tabhost
机器人:layout_width =FILL_PARENT
机器人:layout_height =FILL_PARENT>
<的LinearLayout
    机器人:方向=垂直
    机器人:layout_width =FILL_PARENT
    机器人:layout_height =FILL_PARENT>
    <的FrameLayout
        机器人:ID =@机器人:ID / tabcontent
        机器人:layout_width =FILL_PARENT
        机器人:layout_height =FILL_PARENT
        机器人:layout_weight =1>
        < android.webkit.WebView的android:layout_width =FILL_PARENT机器人:ID =@ + ID / web视图机器人:layout_height =FILL_PARENT机器人:滚动条=无/>
    < /&的FrameLayout GT;
    < TabWidget
        机器人:ID =@机器人:ID /标签
        机器人:layout_width =FILL_PARENT
        机器人:layout_height =WRAP_CONTENT
        机器人:layout_weight =0
        />
< / LinearLayout中>
< / TabHost>

更新:
把web视图之外的的FrameLayout会导致应用程序在与下面的错误启动时崩溃:
了java.lang.RuntimeException:无法创建选项卡的内容,因为找不到视图ID为2131099648

这发生在我的onCreate方法初始化我tabhost是这样的:

  mTab​​Host = 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)。);


解决方案

突围!

我找到了答案,在另一个我自己的问题在post,我没有过去时绊倒:
Why装载有知名度我TabHost的的FrameLayout唯一的孩子= View.GONE?

简单的设置:
。tabHost.getCurrentView()setVisibility(View.VISIBLE);
这将解决这个问题=我又是一个快乐的开发商!

I'm trying to use a webview inside a tabhost that has 4 tabs - all linked to the same webview.

This is great except for one problem:At start up the webview is black.Clicking tab 2,3 or 4 makes it "come alive".

My quick fix was to use setCurrentTab(1) and then back to 0, but this looks ugly, so I figured I might as well ask for a solution as I cannot find anything online.

How can this be fixed? Below is my 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>

Update:Putting the webview outside of the framelayout causes the app to crash at startup with following error:java.lang.RuntimeException: Could not create tab content because could not find view with id 2131099648

This happens when I in the onCreate method initialize my tabhost like this:

    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));
解决方案

Break through!

I found the answer to my own question in another SO post that I didn't stumble upon in the past:Why is my TabHost's FrameLayout's only child loaded with visibility = View.GONE?

Simply setting:tabHost.getCurrentView().setVisibility(View.VISIBLE);That'll fix the issue = I'm a happy developer again!

这篇关于在网页视图= TabHost作为启动黑屏的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-26 16:12