Pass parameters to WebView in Android

The html you want to display in WebView and pass a string to it. Create the file at app/src/main/assets/html/index.html

<!DOCTYPE html>
<html lang="en">
        <meta charset="utf-8">
        <meta http-equiv="X-UA-Compatible" content="IE=edge">
        <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
          #message {
            width: 100%;
            text-align: center;
            font-size: 24px;
        <p id="message">...</p>
        <script type="text/javascript">
                function loadMsg(msg) {
                    document.getElementById("message").innerHTML = msg;

The WebView in a layout file for rendering html pages.


The Android code to load a local html page and pass a string to it.

WebView wvContent = (WebView) findViewById(;
WebSettings webSettings = wvContent.getSettings();
wvContent.setWebViewClient(new WebViewClient() {
public void onPageFinished (WebView view, String url) {
    if (android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.KITKAT) {
        view.evaluateJavascript("loadMsg('How are you today!')", null);
    } else {
        view.loadUrl("javascript:loadMsg('How are you today!')");

Search within Codexpedia

Custom Search

Search the entire web

Custom Search