0

Web ビューを使用しています。Android 2.3で問題なく動作しています。Android 4.0では背景として白い画面が表示されています。データを確認したところ、データが画面に表示されますが、指定した背景の場所に自動的に白い背景が表示されます。また、この白い背景を透明にしようとしましたが、Android 4.0 では機能しません。私の問題に関連するコードを提供しています。これは 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>

アクティビティ ファイル -> ここでは、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");

私を助けてください.... :(

4

2 に答える 2

0

私があなたの問題を正しく理解していれば、白い (または少なくとも白に近い) フォントを使用するコンテンツを表示する webview が表示されています。このため、透明な背景が必要です。

まず最初に、webview が必要な色のレイアウトになっていることを確認します。次に例を示します。

<?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>

次に、確かに、XML から指定された背景色は考慮されていないようなので、明示的に setBackgroundColor を呼び出すことができます。以下のようなもの:

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

それは役に立ちますか?

于 2013-03-25T14:00:23.310 に答える
-1

Android 4.0 バージョンのマニフェスト ファイルで android:hardwareAccelerated="true" を使用しないと、白い画面が表示されます。

于 2013-03-22T07:28:32.893 に答える