Simple use of Android learning ProgressBar

Source: Internet
Author: User

Android provides the ProgressBar control is divided into two, one is a progress bar without progress, a progress bar with progress, if you can calculate the completion of the task then use a progress bar, if you cannot calculate the amount of the task, then use the progress bar without progress. ProgressBar if only using the system provided, it is very simple, only those attribute methods, but the feeling is more rare is the style of ProgressBar, generally do not use the application of the system directly, but on its forehead on the basis of further landscaping.

Key attributes of ProgressBar

        Android:max Maximum        android:proress First progress value        android:secondprogress      Second progress value        android:interminate
    
      is the exact display
    

Maximum: Is the length of the whole ProgressBar

First progress and second progress: Android provides a control can display two progress values at the same time, the most common is used in the player, the first progress generally represents the current playback progress, the second progress generally represents the current buffering progress

is the exact display:

Key methods of ProgressBar

Setprogress set the first progress        setsecondprogress set the second progress        getprogress get the first progress        Getsecondprog                Ress get second progress        Incrementprogressby increase or              decrease the first progress Incrementsecondprogressby increase or decrease the        second progress        Getmax Get maximum Value

I can see the meaning of the above.

A progress bar in the form of a dialog box,

           //properties of the ProgressDialogProgressDialog =NewProgressDialog (progressbaractivity. This);                Progressdialog.setprogressstyle (progressdialog.style_horizontal); Progressdialog.settitle ("TEST"); Progressdialog.setmessage ("Welcome");                Progressdialog.seticon (R.drawable.ic_launcher); //ProgressDialog Properties of the progress barProgressdialog.setmax (100); Progressdialog.setprogress (50); Progressdialog.setindeterminate (false);//Show Progress clearlyProgressdialog.setbutton (progressdialog.button_positive, "OK",NewDialoginterface.onclicklistener () {@Override Public voidOnClick (Dialoginterface Dialog,intwhich) {Toast.maketext (Getbasecontext (),"Thank You", Toast.length_long). Show ();                }                }); //Whether you can exit the dialog box by returning the buttonProgressdialog.setcancelable (true); Progressdialog.show ();

Custom Color Progress bar

<style name= "Widget.ProgressBar.Horizontal" >        <item name= "Android:indeterminateonly" >false </item>        <item name= "android:progressdrawable" > @android:d rawable/progress_horizontal</ item>        <item name= "android:indeterminatedrawable" > @android:d rawable/progress_indeterminate_ horizontal</item>        <item name= "android:minheight" >20dip</item>        <item name= "Android: MaxHeight ">20dip</item>        <item name=" Android:mirrorforrtl ">true</item>    </style>

Locate progressdrawable, and then go to Progress_horizontal.xml to see the style definition of the system Progessbar

<layer-list xmlns:android= "Http://schemas.android.com/apk/res/android" > <item android:id= "@android: ID/ Background "> <shape> <corners android:radius=" 5dip "/> <Gradient Android:startcolor= "#ff9d9e9d"Android:centercolor= "#ff5a5d5a"Android:centery= "0.75"Android:endcolor= "#ff747674"Android:angle= "/>" </shape> </item> <item android:id= "@android: Id/secondaryprogress" &        Gt <clip> <shape> <corners android:radius= "5dip"/> <Gradient Android:startcolor= "#80ffd300"Android:centercolor= "#80ffb600"Android:centery= "0.75"Android:endcolor= "#a0ffcb00"Android:angle= "/>" </shape> </clip> </item> <item android:id= "@a Ndroid:id/progress "> <clip> <shape> <corners android:radius=" 5dip "/&gt                ; <Gradient Android:startcolor= "#ffffd300"Android:centercolor= "#ffffb600"Android:centery= "0.75"Android:endcolor= "#ffffcb00"Android:angle= "/>" </shape> </clip> </item> </layer-list>

Copy this document to the project drawable directory, this document, we can change the color of the progress bar, angle. This changes the style of the progress bar.

Finally, the reporter adds the progressdrawable attribute to the ProgressBar attribute

Simple use of Android learning ProgressBar

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.