Android, Codes and Tips

Just in

12/15/2019

How to set webview post title in ActionBar or ToolBar



After working and searching for hours and you can't get the solution you are looking for. You are welcome to the home of Android Developer. If you have being using Android Studio for writing Java apps, Java codes is everything sensitive raging from capital letters, punctuation errors, misspelled of words and plugin updates.

Android Studio comes up with new updates always which depreciated the older once. A code you write today, use it and develop an app may be outdated and depreciated tomorrow. If you copy somebody's code or forked a code from github, there are chances that the code which worked earlier won't work again unless you do serious editing.


Add the below code to the webPage java file

public class MyWebChromeClient extends WebChromeClient {

        @Override
        public void onReceivedTitle(WebView view, String title) {

            getSupportActionBar().setTitle(title);
            super.onReceivedTitle(view, title);
        }

        @Override
        public void onReceivedIcon(WebView view, Bitmap icon) {

            BitmapDrawable iconDrawable =
                    new BitmapDrawable(getResources(), icon);

            getSupportActionBar().setIcon(iconDrawable);
            super.onReceivedIcon(view, icon);
        }

    }

No comments:

Post a Comment