Android WebView

This post contain all about android webview.
If you are reading this I assume that you know what is webview and just want to use it in your app.



To Use web view you need to first you need to add the webview in your layout

#1 Add webview to layout


1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:orientation="vertical" android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:id="@+id/webview">

    <WebView
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:id="@+id/wview" />
</LinearLayout>

#2 Find the webview
To use the webview you need to find the widget in your activity class.


1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
public class AboutActivity extends AppCompatActivity {

    WebView wview;

    @Override
    protected void onCreate(@Nullable Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.about);

        //find the webview
        wview = (WebView)findViewById(R.id.wview);

    }


}

#3 Load local file to webview
copy your html file in android "assets" folder and pass the html file to loadURL method


1
2
//load the local file from webview
            wview.loadUrl("file///android_asset/aboutm.html");

Comments

Popular posts from this blog

Create Custom View in android MATRIX EFFECT CANVAS tutorial

Xamarin : Simple Calculator Tutorial Visual Studio C#