
How to modify the progress bar of webview or how to create custom progress on top webview?

How to modify the progress bar of webview or how to create custom progress on top webview?
 
    
     
    
    To implement a custom progress bar, you'll need a Runnable thread and a message handler which will keep updating your progress bar.
Check the snippet below:-
Get your progress bar and then start the new Thread
myProgressBar=(ProgressBar)findViewById(R.id.progressbar);
new Thread(myThread).start();
New Thread:-
private Runnable myThread = new Runnable(){
@Override
public void run() {
while (myProgress<100){
try{
myHandle.sendMessage(myHandle.obtainMessage());
Thread.sleep(1000);
}
catch(Throwable t){
}
}
}
}
The message sent from the try block above, will be handled in the handleMessage method of your Handler below:-
Handler myHandle = new Handler(){
@Override
public void handleMessage(Message msg) {
myProgress++;
myProgressBar.setProgress(myProgress);
}
}
Hope this helps!
 
    
    That was for custom progress bar. If you need to play around with the Webview then I think this should help you out.
A WebView has several customization points where you can add your own behavior. They are:
Creating and setting a WebChromeClient subclass. This class is called when something that might impact a browser UI happens, for instance, progress updates and JavaScript alerts are sent here.
Creating and setting a WebViewClient subclass. It will be called when things happen that impact the rendering of the content, eg, errors or form submissions. You can also intercept URL loading here(via shouldOverrideUrlLoading()).
// To display the progress in the activity title bar, like the
// browser app does.
getWindow().requestFeature(Window.FEATURE_PROGRESS);
webview.getSettings().setJavaScriptEnabled(true); // javascript if needed.
final Activity activity = this;
webview.setWebChromeClient(new WebChromeClient() {
   public void onProgressChanged(WebView view, int progress) {
     // The progress meter will automatically disappear when we reach 100%
     activity.setProgress(progress * 1000);
   }
 });
 webview.setWebViewClient(new WebViewClient() {
   public void onReceivedError(WebView view, int errorCode, String description, String failingUrl) {
            Toast.makeText(activity, "Page Load Error! " + description, Toast.LENGTH_SHORT).show();
   }
 });
 webview.loadUrl("http://www.stackoverflow.com");
