2013-10-01 64 views
1

我在我的应用程序的简单的Android的WebView。我已在编码URL格式的web视图的内容,但它没有显示图像,但它示出了网页视图面板。这里是我试过的Android的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> 

的网页流量的web内容编码格式给出。 但解码的内容是

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

回答

0

你可能忘了,包括在Android清单文件INTERNET权限。

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

否则你的HTML内容看起来不错,它的装载太的WebView与蓝天的彩色图像。

enter image description here

+0

请看看编辑过的问题。我已添加清单。我已经给了互联网许可,但仍然没有加载。我在设备上的网络连接也 – user2813821

+0

我的设备API级别为16和互联网是工作压力太大,并在明显的权限给予,但仍没有运气:( – user2813821