Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <h1>You can build a local WebView in the following way</h1> <ul> <li>The Activity (LocalWebviewActivity.java)</li> <li>The Layout (activity_localwebview.xml)</li> <li>The Assets folder (in the root of "assets" folder, create the folder "css" and place "style.css" in here)</li> <li>You refer to JS files the same way you refer to CSS StyleSheets </li> </ul> <h2>LocalWebviewActivity.java</h2> <pre><code>import android.app.Activity; import android.os.Bundle; import android.webkit.WebView; public class LocalWebviewActivity extends Activity { WebView myWebView; StringBuilder mySBcontent; @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_localwebview); myWebView = (WebView) findViewById(R.id.webkit); mySBcontent = new StringBuilder(); mySBcontent.append("&lt;html&gt;"); mySBcontent.append("&lt;head&gt;"); mySBcontent.append("&lt;link type='text/css' rel='stylesheet' href='css/style.css'&gt;"); mySBcontent.append("&lt;/head&gt;"); mySBcontent.append("&lt;body&gt;"); mySBcontent.append("&lt;h1&gt;My Heading&lt;/h1&gt;"); mySBcontent.append("&lt;p&gt;My HTML content&lt;/p&gt;"); mySBcontent.append("&lt;p&gt;&lt;img style='width:150px;' src='myImg.png' /&gt;&lt;/p&gt;"); mySBcontent.append("&lt;/body&gt;"); mySBcontent.append("&lt;/html&gt;"); myWebView.loadDataWithBaseURL("file:///android_asset/", mySBcontent.toString(), "text/html", "UTF-8", ""); } } </code></pre> <h2>activity_localwebview.xml</h2> <pre><code>&lt;?xml version="1.0" encoding="utf-8"?&gt; &lt;LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:orientation="vertical" android:layout_width="fill_parent" android:layout_height="fill_parent"&gt; &lt;WebView android:id="@+id/webkit" android:layout_width="fill_parent" android:layout_height="fill_parent"/&gt; &lt;/LinearLayout&gt; </code></pre>
    singulars
    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.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      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