Android realizes WebView with progress bar

Source: Internet
Author: User

If you do not use the system-titlebar (that is, the activity is set @android:style/theme.notitlebar), you need to write the progress bar yourself, which encapsulates a custom control and a public activity that loads the Web page for ease of use.

One, screenshot

Two, custom controls

/** * WebView * @author Farmer @see * * * * * * * * * * * * * with progress bar * */@Suppr
    
    Esswarnings ("deprecation") public class Progresswebview extends WebView {private ProgressBar ProgressBar;
        Public Progresswebview (context, AttributeSet attrs) {Super (context, attrs); ProgressBar = new ProgressBar (context, NULL, Android.)
        R.attr.progressbarstylehorizontal);
        Progressbar.setlayoutparams (New Layoutparams (layoutparams.fill_parent, 3, 0, 0));
        AddView (ProgressBar);
        Setwebviewclient (New Webviewclient () {});
    Setwebchromeclient (New Webchromeclient ()); The public class Webchromeclient extends Android.webkit.WebChromeClient {@Override public void Onp Rogresschanged (webview view, int newprogress) {if (newprogress = =) {Progressbar.setvisib
            Ility (GONE); else {if (progressbar.getvisibility () = =GONE) progressbar.setvisibility (VISIBLE);
            Progressbar.setprogress (newprogress);
        } super.onprogresschanged (view, newprogress); } @Override protected void onscrollchanged (int l, int t, int oldl, int Oldt) {Layoutparam
        S LP = (Layoutparams) progressbar.getlayoutparams ();
        lp.x = l;
        LP.Y = t;
        PROGRESSBAR.SETLAYOUTPARAMS (LP);
    Super.onscrollchanged (L, T, OLDL, Oldt); }
}

See more highlights of this column: http://www.bianceng.cnhttp://www.bianceng.cn/OS/extra/

Related Article

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.