Layout Page section:
<?xml version= "1.0" encoding= "Utf-8"?>
<relativelayout xmlns:android= "Http://schemas.android.com/apk/res/android"
Xmlns:tools= "Http://schemas.android.com/tools"
Android:id= "@+id/activity_main"
Android:layout_width= "Match_parent"
android:layout_height= "Match_parent"
android:background= "@color/colorprimary"
tools:context= "Com.example.administrator.myprogressbar.MainActivity" >
<progressbar
Android:id= "@+id/progressbar"
Android:layout_width= "Match_parent"
android:layout_height= "20DP"
style= "@style/base.widget.appcompat.progressbar.horizontal"
/>
<webview
Android:id= "@+id/webview"
Android:layout_width= "Match_parent"
android:layout_height= "Match_parent"
android:layout_below= "@id/progressbar"
></WebView>
</RelativeLayout>
-----------------------
Activity section
Package Com.example.administrator.myprogressbar;
Import Android.os.Bundle;
Import android.support.v7.app.AppCompatActivity;
Import Android.view.View;
Import android.webkit.WebChromeClient;
Import android.webkit.WebSettings;
Import Android.webkit.WebView;
Import android.webkit.WebViewClient;
Import Android.widget.ProgressBar;
Import Butterknife. BindView;
Import Butterknife. Butterknife;
public class Mainactivity extends Appcompatactivity {
@BindView (R.id.progressbar)
ProgressBar ProgressBar;
@BindView (R.id.webview)
WebView WebView;
@Override
protected void OnCreate (Bundle savedinstancestate) {
Super.oncreate (savedinstancestate);
Setcontentview (R.layout.activity_main);
Butterknife.bind (this);
Set Web Type
Webview.getsettings (). Setcachemode (Websettings.load_cache_else_network);
Loading Web pages
Webview.loadurl ("http://www.baidu.com");
Set monitoring: Porgressbar Explicit
Webview.setwebchromeclient (New Webchromeclient () {
@Override
public void onprogresschanged (WebView view, int newprogress) {
Super.onprogresschanged (view, newprogress);
Progressbar.setprogress (newprogress);
Disappears when ProgressBar loading is complete
if (progressbar.getprogress () ==100) {
Progressbar.setvisibility (View.gone);//Disappear
}
}
});
Block Local browser
Webview.setwebviewclient (New Webviewclient () {
@Override
public boolean shouldoverrideurlloading (WebView view, String URL) {
View.loadurl (URL);
return true;
}
});
}
}
---------------
Finally, a sentence is implemented in the XML file:
Open the Mobile Web project code module