How to get loaded web page title in Android WebView?

You’ll have to use a custom WebViewClient to get this done.
You will override the onPageFinished() method so when a new page finishes loading you can set the webview to the appropriate title.

Below is a sample implementation of the above:

    WebView mWebView = (WebView) findViewById(R.id.mwebview);
    mWebView.setWebViewClient(new WebViewClient() {
        @Override
        public void onPageFinished(WebView view, String url) {
            ExperimentingActivity.this.setTitle(view.getTitle());
        }
    });

You’re a going to do that where you’re initializing your webview.
Replace the “ExperimentingActivity” to whatever you activity’s name is.

If you’re already overriding the WebViewClient, just add this function or the code inside to your already existing function.

You can get more info on the classes and functions I’m using here at:

Android Developers: Activity – setTitle()

Android Developers: WebViewClient

Android Developers: WebView

Leave a Comment