1

我的应用程序中有一个简单的 android webview。我已经以编码的 url 格式给出了 webview 内容,但它没有显示图像,而是显示了 webview 面板。这是我尝试过的代码

public class MainActivity extends Activity {
WebView webVw;
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        webVw=(WebView)findViewById(R.id.webVw);
        String webContent="%3Cdiv%20style%3D%22width%3A100%25%3Bheight%3A100%25%3Bposition%3Arelative%3Bleft%3A.1%25%3Btop%3A.1%25%22%3E%3Ca%20href%3D%22javascript%3A%20void(0)%22%20%20target%3D%22_blank%22%20%3E%3Cimg%20src%3D%22https%3A%2F%2Fencrypted-tbn3.gstatic.com%2Fimages%3Fq%3Dtbn%3AANd9GcSQYCrMOneFgRqcDAsgBrcCCMUJXKANqHm7V2Facbr8afLzsW19%22%20style%3D%22position%3Aabsolute%3Bwidth%3A41.875%25%3Bheight%3A26%25%3Bleft%3A56.875%25%3Btop%3A58.86889460154242%25%22%20%2F%3E%3C%2Fa%3E%3C%2Fdiv%3E";

        webVw.loadData(webContent, "text/html","utf-8");
        //(webContent, "text/html","utf-8");
    }
}

这是布局文件

 <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
        xmlns:tools="http://schemas.android.com/tools"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:paddingBottom="@dimen/activity_vertical_margin"
        android:paddingLeft="@dimen/activity_horizontal_margin"
        android:paddingRight="@dimen/activity_horizontal_margin"
        android:paddingTop="@dimen/activity_vertical_margin"
        tools:context=".MainActivity" >

        <WebView android:layout_width="fill_parent" android:layout_height="fill_parent" android:id="@+id/webVw"/>
</RelativeLayout>

网页视图的网页内容以编码格式给出。但解码后的内容是

<div style="width:100%;height:100%;position:relative;left:.1%;top:.1%"><a href="javascript: void(0)"  target="_blank" ><img src="https://encrypted-tbn3.gstatic.com/images?q=tbn:ANd9GcSQYCrMOneFgRqcDAsgBrcCCMUJXKANqHm7V2Facbr8afLzsW19" style="position:absolute;width:41.875%;height:26%;left:56.875%;top:58.86889460154242%" /></a></div>

现在的问题是没有显示图像。这是清单

<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
    package="com.example.webviewdemo"
    android:versionCode="1"
    android:versionName="1.0" >

    <uses-sdk
        android:minSdkVersion="8"
        android:targetSdkVersion="17" />
 <uses-permission android:name="android.permission.INTERNET" />
    <application
        android:allowBackup="true"
        android:icon="@drawable/ic_launcher"
        android:label="@string/app_name"
        android:theme="@style/AppTheme" >
        <activity
            android:name="com.example.webviewdemo.MainActivity"
            android:label="@string/app_name" >
            <intent-filter>
                <action android:name="android.intent.action.MAIN" />

                <category android:name="android.intent.category.LAUNCHER" />
            </intent-filter>
        </activity>
    </application>

</manifest>
4

1 回答 1

0

您可能忘记在 Android 清单文件中包含 INTERNET 权限。

<uses-permission android:name="android.permission.INTERNET"/>

否则,您的 HTML 内容看起来不错,并且它也在带有蓝天彩色图像的 WebView 中加载。

在此处输入图像描述

于 2013-10-01T09:15:30.973 回答