简体   繁体   English

webview在android 2.3上运行良好时显示android 4.0的白屏

[英]webview is showing white screen for android 4.0 while it is working well on android 2.3

I am using a web view. 我正在使用网络视图。 It is working very fine on android 2.3. 它在android 2.3上工作得很好。 but it is showing a white screen as background in android 4.0. 但它在android 4.0中显示为背景的白色屏幕。 I checked for the data and data is coming on screen but automatically a white background is coming at the place of my given background. 我检查了数据,并且数据正在显示在屏幕上,但是在我给定背景的地方会自动出现白色背景。 I also tried to make this white background as transparent but it is not working for android 4.0. 我也试图使白色背景透明,但不适用于android 4.0。 I am providing code related to my problem. 我正在提供与我的问题有关的代码。 this is webView.xml 这是webView.xml

                    <ImageView
                        android:id="@+id/backButtonZodiacSign"
                        android:layout_width="wrap_content"
                        android:layout_height="0dp"
                        android:layout_marginLeft="10dp"
                        android:layout_weight="0.09"
                        android:contentDescription="@drawable/back3"
                        android:src="@drawable/back3" />

                    <ScrollView
                        android:id="@+id/zodiac_calender_scroll"
                        android:layout_width="wrap_content"
                        android:layout_height="0dp"
                        android:layout_weight="0.91" >`<WebView
                                android:id="@+id/webViewZodiacCalender"
                                android:layout_width="match_parent"
                                android:layout_height="match_parent"
                                android:background="@android:color/transparent"
                                android:layerType="software"
                                android:layout_alignParentBottom="true"
                                android:layout_below="@+id/zodiac_calender_relative"
                                 />

                    </ScrollView>

                </LinearLayout>

And activity file->here html data is coming dynamically from other activity. 活动文件->此处html数据是动态地来自其他活动的。

            String sign = null;
                sign = savedInstanceState.getString("zodiacSign");
                zordic_calender_sign = (TextView) findViewById(R.id.zodiac_calender_sign);
                zordic_calender_sign.setText(sign.substring(0, 1).toUpperCase()
                        + sign.substring(1));

                image = (ImageView) findViewById(R.id.zodiac_calender_image);
                String uriZodiacSign = "drawable/" + sign;
                int imageZodiacSign = getResources().getIdentifier(uriZodiacSign, null,
                        getPackageName());
                Drawable drawableZodiacSign = getResources().getDrawable(
                        imageZodiacSign);
                image.setImageDrawable(drawableZodiacSign);

                webView = (WebView) findViewById(R.id.webViewZodiacCalender);
                backButton = (ImageView) findViewById(R.id.backButtonZodiacSign);

                webView.setBackgroundColor(Color.TRANSPARENT);
                webView.loadUrl("file:///android_asset/" + sign + ".html");

Please help me.... :( 请帮我.... :(

If I understand your problem correctly, then you're having a webview displaying some content that uses a white (or at least close to white) font. 如果我正确理解了您的问题,则说明您的网络视图显示的内容使用白色(或至少接近白色)字体。 For this reason you need the transparent background. 因此,您需要透明的背景。

First of all make sure the webview is in a layout with any color you need, for example: 首先,请确保Web视图处于所需颜色的布局中,例如:

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:background="@android:color/black"
    android:orientation="vertical" >

    <ImageButton
        android:id="@+id/imageButton1"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:contentDescription="@null"
        android:src="@drawable/sample_back" />

    <WebView
        android:id="@+id/webContainer"
        android:layout_width="match_parent"
        android:layout_height="match_parent" />

</LinearLayout>

Next, indeed, it seems the background color specified from XML doesn't get into account so you could call explicitly setBackgroundColor. 接下来,的确确实没有考虑到XML指定的背景色,因此您可以显式调用setBackgroundColor。 Something like below: 如下所示:

webContainer = (WebView) findViewById(R.id.webContainer);
webContainer.setBackgroundColor(0x00000000);
webContainer.loadUrl("the_url_to_load");

Would that help? 有帮助吗?

对于Android 4.0版本,请在清单文件中使用android:hardwareAccelerated =“ true”,否则它将显示白屏。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM