Android progress bar usage

Source: Internet
Author: User
Android progress bar 1. Implementation Effect

 

 

2. layout code

Write a my_browser.xml file to store the webview.

<?xml version="1.0" encoding="utf-8"?><LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"    android:layout_width="fill_parent"    android:layout_height="fill_parent"    android:orientation="vertical" >        <WebView        android:id="@+id/webView"        android:layout_width="fill_parent"        android:layout_height="fill_parent" /></LinearLayout>
Progress bar Layout

Then write a broser. xml file to store the progress bar

<?xml version="1.0" encoding="utf-8"?> <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="fill_parent" android:layout_height="fill_parent"> <TextView android:id="@+id/tvtitle" android:layout_width="fill_parent" android:layout_height="wrap_content" android:focusableInTouchMode="true" android:singleLine="true" android:ellipsize="marquee" android:focusable="false" android:marqueeRepeatLimit="marquee_forever" android:textSize="20sp" android:layout_centerVertical="true"/> <ProgressBar android:id="@+id/pb" android:layout_width="fill_parent" android:layout_height="wrap_content" style="?android:attr/progressBarStyleHorizontal" android:visibility="gone" android:layout_alignParentBottom="true" ></ProgressBar> </RelativeLayout>

 

Webchromeclient

Override onprogresschanged and onreceivedtitle events (use the animation to fade away after the progress bar is loaded)

/**** Mywebchromeclient. Java * copyright (c) 2012
* Creation: cuiran 3:05:34 */package COM. cayden. citygirl. activity; import android. app. activity; import android. view. view; import android. view. animation. animation; import android. view. animation. animationutils; import android. webKit. webchromeclient; import android. webKit. webview; import android. widget. progressbar; import android. widget. textview;/**** todo * @ author cuiran * @ version todo */public class mywebchromeclient extends webchromeclient {private activity; private progressbar Pb; private animation; private textview tvtitle; public mywebchromeclient (activity) {This. activity = activity;} @ override public void onprogresschanged (webview view, int newprogress) {Pb = (progressbar) activity. findviewbyid (R. id. PB); Pb. setmax (100); If (newprogress <100) {If (Pb. getvisibility () = view. gone) Pb. setvisibility (view. visible); Pb. setprogress (newprogress);} else {Pb. setprogress (100); animation = animationutils. loadanimation (activity, R. anim. animation); // run the animation Pb. startanimation (animation); // sets the visibility of the spinner to an invisible Pb. setvisibility (view. invisible);} super. onprogresschanged (view, newprogress) ;}@ override public void onreceivedtitle (webview view, String title) {tvtitle = (textview) activity. findviewbyid (R. id. tvtitle); tvtitle. settext (title); super. onreceivedtitle (view, title );}}

Animated style Res/anim/animation. xml of the progress bar

<?xml version="1.0" encoding="utf-8"?> <set xmlns:android="http://schemas.android.com/apk/res/android"> <alpha android:fromAlpha="1.0" android:toAlpha="0.0" android:duration="700"/> </set>
5. Program startup
/*** Progressactivity. java * copyright (c) 2012 * created: cuiran 2012-10-16 3:13:49 */package COM. cayden. citygirl. activity; import android. app. activity; import android. OS. bundle; import android. view. window; import android. webKit. webview;/*** todo * @ author cuiran * @ version todo */public class progressactivity extends activity {private webview browser; @ override public void oncreate (bundle savedinstancestate) {super. oncreate (savedinstancestate); getwindow (). requestfeature (window. feature_custom_title); setcontentview (R. layout. my_browser); getwindow (). setfeatureint (window. feature_custom_title, R. layout. broser); browser = (webview) findviewbyid (R. id. webview); // currentwebview = browser; browser. setwebchromeclient (New mywebchromeclient (progressactivity. this); browser. loadurl ("http://shop.paipai.com/731681975 ");}}

 

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.