0

編集:私の現在のソリューション。json を div タグでラップし、同様に透明に設定しました。

リモートで json オブジェクトから webview を作成しています。

{
"message": "<p style=\"color:#EEEEEE;background-color:transparent;font-family:'Arial Narrow','Nimbus Sans L',sans-serif;\"><\/p><p style=\"color:#EEEEEE;background-color:transparent;font-family:'Arial Narrow','Nimbus Sans L',sans-serif;\">The mission of the Canton Police Department is to protect the lives and properties of the citizens of Canton, enforce all city, state, and federal law<\/p>",
"nationalad": ""
}

WebView の背景を透明にすることができます。ただし、半透明ではありません。これを試すと:

webView1.setBackgroundColor(Color.argb(128, 00, 00, 000));

右側に小さな垂直の透明なストリップがある黒い背景が表示されます。完全に透明にするには:

webView1.setBackgroundColor(0x00000000);  

JSONを取り込む方法は次のとおりです。

  try{
                JSONObject json = new JSONObject(result);
                JSONArray nameArray = json.names();
                JSONArray valArray = json.toJSONArray(nameArray);
                for (int i = 0; i < valArray.length(); i++)
                {      
                    WebView webView1 = (WebView) findViewById(R.id.webView1);
                   // webView1.setBackgroundColor(0x00000000);

                    //webView1.loadDataWithBaseURL(null, valArray.getString(0), "text/html", "utf-8", null);   
                    webView1.setBackgroundColor(Color.argb(128, 00, 00, 00));
                }     

編集:XML

    <!-- Included header.xml here -->

    <ViewStub
        android:id="@+id/vsHeader"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:inflatedId="@+id/header"
        android:layout="@layout/header" />

    <LinearLayout
        android:id="@+id/linearLayout1"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:background="@drawable/cpd"
        android:gravity="center|center_horizontal|center_vertical"
        android:orientation="vertical"
        android:paddingBottom="50dp" >

        <WebView
            android:id="@+id/webView1"
            android:layout_width="250dp"
            android:layout_height="300dp"
            />

    </LinearLayout>

</LinearLayout>         

ここに画像の説明を入力

4

3 に答える 3

4

これは私のために働く:

ウェブページの本文:

background-color:transparent

あなたのJavaアクティビティで:

webView.loadUrl("yourwebpage");
webView.setBackgroundColor(0x00000000); 
webView.setLayerType(WebView.LAYER_TYPE_SOFTWARE, null);

また、アクティビティに対してhardwareAccelerated falseを設定する必要があります。

android:hardwareAccelerated="false"
于 2012-09-27T08:28:34.257 に答える
2

setBackgroundColor 呼び出しを次のように変更します。

    webView1.setBackgroundColor(0xAA000000);  

これにより、半透明の黒が得られます。最初の 2 つのエントリはアルファ値です。値が小さいほど、色はより透明になります。

于 2012-04-19T18:47:37.223 に答える