Categories

Follow Us @web_learners

Friday, April 3, 2020

How to Add Progress Bar in App | Webview App Development Series Part 4

Hi, In the previous post I have shown Open Url within the Webview App Not in Browser  Today I will show you how to add a Progress bar in the Android /Webview app. Watch the full video for better understanding. Let's start.



First, you need to go activity_main.xml, in the activity_main.xml file above WebView(the previous post I have shown how to set up WebView) you need to take a Progress Bar.you need to select "width" is "match_parent" and "height" is "wrap_content".Then you need to take an Id, I have given that id name is progressBar, then have to take ProgressBar Style like you can take circle type, Horizontal Bar type e.t.c.I am taking Horizontal type ProgressBarStyleHorizontal

Code:
[


We have finished our code for the progress bar in activity_main.xml. So, the final code will be in activity_main.xml is:

Code:


Now we will write code in MainActivity.java file, First, we will take a global variable ProgressBar, I am giving the name of that variable is progressBar.

Code:




Now we will retrieve ProgressBar layout from activity_main.xml file and will store in our global variable progressBar.
Code:


Then we will write a WebChromeClient() function, in that function we will write code for if our website has not loaded 100% and our progressBar has gone, then ProgressBar visibility will be Visible, else if our website loaded finish and still showing progress bar then ProgressBar visibility will be Gone from Webview App.
Code:



That's it. We have finished writing code in activity_main.xml and MainActivity.java file. Now we will run our Project.

As you can see in my above picture my app is running in Emulator, And you can see its showing ProgressBar and work perfectly also, So we have successfully added ProgressBar in our Webview App. Thanks.

2 comments:

  1. Thanks for your tutorials.
    I'am getting web page not available

    ReplyDelete
  2. Hello
    first of all thank for your valuable tutorial.
    nut i have one issue .
    i am following your all steps but one issue is created .can you solve this if possible
    issue
    when i run a app then app is fine but issue in whatsapp page. when i click on whatsapp icon then the message is shownn - webpage not available.
    you can check my website is www.mrweddingz.com. make and click on whatsapp icon.
    if you find and solve this problem .plz make a tutorial for all users.thanx

    ReplyDelete