Android progress bar

Source: Internet
Author: User

XML reference

<ProgressBar Android:id="@+id/pb_progressbar"style="@style/styleprogressbarmini"Android:layout_width="fill_parent"Android:layout_height="40dip"Android:layout_margin="30DP"Android:background="@drawable/SHAPE_PROGRESSBAR_BG"Android:max=" -"android:progress="0"/>
ProgressBar

Style Styles.xml

<Resources>    <!--Base application theme, dependent on API level.    This theme are replaced by Appbasetheme from Res/values-vxx/styles.xml on newer devices.  -    <stylename= "Appbasetheme"Parent= "Android:Theme.Light">        <!--Theme customizations available in newer API levels can go in res/values-vxx/styles.xml, while C        Ustomizations related to Backward-compatibility can go.  -    </style>    <!--application theme. -    <stylename= "Apptheme"Parent= "Appbasetheme">        <!--All customizations, that is, specific to a particular api-level can go. -    </style>    <stylename= "Styleprogressbarmini"Parent= "@android: Style/widget.progressbar.horizontal">        <Itemname= "Android:maxheight">50dip</Item>        <Itemname= "Android:minheight">10dip</Item>        <Itemname= "Android:indeterminateonly">False</Item>        <Itemname= "Android:indeterminatedrawable">@android:d Rawable/progress_indeterminate_horizontal</Item>        <Itemname= "Android:progressdrawable">@drawable/shape_progressbar_mini</Item>    </style></Resources>
Styles.xml

Border

<?XML version= "1.0" encoding= "Utf-8"?><Shapexmlns:android= "Http://schemas.android.com/apk/res/android"Android:shape= "Rectangle" >    <!--color of border fills -     <SolidAndroid:color= "#cecece" />    <!--set the four corners of the progress bar as arcs -     <!--Android:radius radius of Arc -    <CornersAndroid:radius= "90DP" />    <!--padding: The interval of the boundary -    <paddingAndroid:bottom= "1DP"Android:left= "1DP"Android:right= "1DP"Android:top= "1DP" /></Shape>
Shape_progressbar_bg.xml

Fill

<?XML version= "1.0" encoding= "Utf-8"?><layer-listxmlns:android= "Http://schemas.android.com/apk/res/android" >    <ItemAndroid:id= "@android: Id/background">        <Shape>            <CornersAndroid:radius= "5dip" />                <GradientAndroid:angle= "+"Android:centery= "0.75"Android:endcolor= "@color/white"Android:startcolor= "@color/white" />        </Shape>    </Item>    <ItemAndroid:id= "@android: id/secondaryprogress">        <Clip>            <Shape>                <CornersAndroid:radius= "0dip" />                <GradientAndroid:angle= "+"Android:centery= "0.75"Android:endcolor= "#df0024"Android:startcolor= "#df0024" />            </Shape>        </Clip>    </Item>    <ItemAndroid:id= "@android: id/progress">        <Clip>            <Shape>                <CornersAndroid:radius= "5dip" />                <GradientAndroid:angle= "+"Android:centery= "0.75"Android:endcolor= "@color/blue"Android:startcolor= "@color/blue" />            </Shape>        </Clip>    </Item></layer-list>
Shape_progressbar_mini.xml

Background settings

ImportAndroid.os.Bundle;ImportAndroid.os.Handler;Importandroid.app.Activity;ImportAndroid.util.Log;ImportAndroid.view.Menu;ImportAndroid.widget.ProgressBar; Public classMainactivityextendsActivity {PrivateProgressBar Pb_progressbar; @Overrideprotected voidonCreate (Bundle savedinstancestate) {Super. OnCreate (savedinstancestate);        Setcontentview (R.layout.activity_main); Pb_progressbar=(ProgressBar) Findviewbyid (R.id.pb_progressbar); Handler.postdelayed (runnable, delyed); //Start Timer} @Override Public BooleanOncreateoptionsmenu (Menu menu) {//inflate the menu; This adds items to the action bar if it is present.getmenuinflater (). Inflate (R.menu.main, menu); return true; }    //Timing Device    Private intDelyed= 500; Private intTimeout=0; Handler Handler=NewHandler (); Runnable Runnable=NewRunnable () {@Override Public voidrun () {Try{handler.postdelayed ( This, delyed); TimeOut++;                            Pb_progressbar.setprogress (TimeOut); } Catch(Exception e) {LOG.E ("->runnable Timer", e.tostring ()); }        }    };}
Java Code

Android progress bar

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.