Open the Mobile Web project code module

Source: Internet
Author: User

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.