fastread homefastrread library fastread menu

Android : WebView

Tutorial by:      Date: 2018-01-23 04:18:20

❰ Previous Next ❱

Android WebView is utilized to show website page in android. The site page can be stacked from same application or URL. It is utilized to show online substance in android action. 

Android WebView utilizes webkit motor to show website page. 

The android.webkit.WebView is the subclass of AbsoluteLayout class. 

The loadUrl() and loadData() techniques for Android WebView class are utilized to load and show site page. 

How about we see the straightforward code to show fastread.in site page utilizing web see.


WebView mywebview = (WebView) findViewById(R.id.webView1);  
mywebview.loadUrl("http://www.fastread.in/");  

Let's see the simple code to display HTML web page using web view. In this case, html file must be located inside the asset directory.


WebView mywebview = (WebView) findViewById(R.id.webView1);  
mywebview.loadUrl("file:///android_asset/myresource.html");  

Let's see another code to display HTML code of a string.


String data = "";  
mywebview.loadData(data, "text/html", "UTF-8");  

Android WebView Example

Let's see a simple example of android webview.

activity_main.xml

File: activity_main.xml

<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"  
    tools:context=".MainActivity" >  

    <WebView  
        android:id="@+id/webView1"  
        android:layout_width="match_parent"  
        android:layout_height="match_parent"  
        android:layout_alignParentTop="true"  
        android:layout_centerHorizontal="true"  
        android:layout_marginTop="42dp" />  
RelativeLayout>  

Activity class

File: MainActivity.java

package com.example.webview;  
import android.os.Bundle;  
import android.app.Activity;  
import android.view.Menu;  
import android.webkit.WebView;  

public class MainActivity extends Activity {  

    @Override  
    protected void onCreate(Bundle savedInstanceState) {  
        super.onCreate(savedInstanceState);  
        setContentView(R.layout.activity_main);  
        WebView mywebview = (WebView) findViewById(R.id.webView1);  

         //mywebview.loadUrl("http://www.fastread.in/");  

        /*String data = ""; 
        mywebview.loadData(data, "text/html", "UTF-8"); */  

        mywebview.loadUrl("file:///android_asset/myresource.html");  
    }  

    @Override  
    public boolean onCreateOptionsMenu(Menu menu) {  
        // Inflate the menu; this adds items to the action bar if it is present.  
        getMenuInflater().inflate(R.menu.activity_main, menu);  
        return true;  
    }  

} 

Hello, fastread!

Hello, fastread!

❰ Previous Next ❱