Note that there are some explanatory texts on larger screens.

plurals
  1. POImages are not displayed while loading html file in android web view
    primarykey
    data
    text
    <p>I need to load a html file which will display images in android emulator. I have a separate css file and html fie and images to be displayed in /assets folder of my application. I read the css file and html file using getAssets(). I tried to load the html file using loadData() method because i am in the situation to use only string to get html file in a string and load the html file only by using that string but not by using "file:///android_asset/eppi.html". Can anyone say the solution?.You can understand from my following code. thanks in advance.</p> <p>my MainActivity.java code:</p> <pre><code> package com.exercise.AndroidHTML; import java.io.InputStream; import java.io.IOException; import android.annotation.SuppressLint; import android.app.Activity; import android.os.Bundle; import android.webkit.WebSettings; import android.webkit.WebView; import android.content.res.AssetManager; public class AndroidHTMLActivity extends Activity { WebView myBrowser; String html; String css; String HTML; /** Called when the activity is first created. */ @SuppressLint("SetJavaScriptEnabled") @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.main); myBrowser = (WebView)findViewById(R.id.mybrowser); AssetManager assetmanager=getAssets(); InputStream input; try{ input= assetmanager.open("eppi.html"); int size=input.available(); byte[] buffer=new byte[size]; input.read(buffer); input.close(); html=new String(buffer); } catch (IOException e){ e.printStackTrace(); } try{ InputStream input1= assetmanager.open("eppi.css"); int size=input1.available(); byte[] buffer=new byte[size]; input1.read(buffer); input1.close(); css=new String(buffer); }catch (IOException e){ e.printStackTrace(); } HTML=css+html; myBrowser.getSettings().setJavaScriptEnabled(true); WebSettings settings = myBrowser.getSettings(); settings.setDefaultTextEncodingName("utf-8"); myBrowser.loadData(HTML,"text/html","utf-8"); } } </code></pre> <p>my eppi.css file:</p> <pre><code>&lt;html&gt; &lt;head&gt; &lt;style&gt; #header{ height:80px; width:320px; position:absolute; background-color:#000000; } #text{ height:80px; width:159px; position:absolute; color:#806C00; } #logo{ top:2px; left:200px; height:80px; width:97px; position:absolute; } #image{ top:79px; height:80px; width:159px; position:absolute; } #image1{ top:79px; left:159px; height:80px; width:161px; position:absolute; } #image2{ top:158px; height:80px; width:159px; position:absolute; } #image3{ top:158px; left:159px; height:80px; width:161px; position:absolute; } #body{ margin:0; padding:0; } &lt;/style&gt; &lt;/head&gt; </code></pre> <p>my eppi.html code:</p> <pre><code>&lt;body id="body"&gt; &lt;div id="header"&gt; &lt;div id="text"&gt; &lt;center&gt; h4&gt;&lt;b&gt;&lt;i&gt;The Show Welcomes You&lt;/i&gt;&lt;/b&gt;&lt;/h4&gt; &lt;/center&gt; &lt;/div&gt; &lt;div id="logo"&gt; &lt;img src="logo.png" width="100" height="75"&gt; &lt;/div&gt; &lt;/div&gt; &lt;div id="image"&gt; &lt;a href="Media.html"&gt;&lt;img src="mine.png" width="159" height="80"/&gt;&lt;/a&gt; &lt;/div&gt; &lt;div id="image1"&gt; &lt;a href="Trading.html"&gt;&lt;img src="offers.png" width="161" height="80"/&gt;&lt;/a&gt; &lt;/div&gt; &lt;div id="image2"&gt; &lt;a href="Hours.html"&gt;&lt;img src="horse.png" width="159" height="80"/&gt;&lt;/a&gt; &lt;/div&gt; &lt;div id="image3"&gt; &lt;a href="Release.html"&gt;&lt;img src="entering.png" width="161" height="80"/&gt;&lt;/a&gt; &lt;/div&gt; &lt;/body&gt; &lt;/html&gt; </code></pre>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload