Chapter 30 Browsing the Web and WebView
Using WebChromeClient to spruce things up
Since you are taking the time to create your own WebView, let’s spruce it up a bit by adding a
progress bar and updating the toolbar’s subtitle with the title of the loaded page. Crack open
fragment_photo_page.xml once again.
Drag in a ProgressBar as a second child for your ConstraintLayout. Use the ProgressBar
(Horizontal) version of ProgressBar. Delete the WebView’s top constraint, and then set its height to
Fixed so that you can easily work with its constraint handles.
With that done, create the following additional constraints:
- from the ProgressBar to the top, right, and left of its parent
- from the WebView’s top to the bottom of the ProgressBar
With that done, change the height of the WebView back to Any Size, change the ProgressBar’s height to
wrap_content, and change the ProgressBar’s width to Any Size.
Finally, select the ProgressBar and move your attention to the properties window. Change the
visibility to gone and change the tools visibility to visible. Rename its ID to progress_bar.
Your result will look like Figure 30.2.
Figure 30.2 Adding a progress bar