Customizing the Android progress bar ProgressBar style

Source: Internet
Author: User

Progress bar in Android app anywhere or see, is to provide users with a hint, to increase the user's experience! The progress bar style is varied, has a round, has a bar, has the vertical direction, also has the horizontal direction. The Android system is also available in several default styles, and today we talk about custom style ProgressBar.

Here is a small (and very small) example:

-------------------------XML Layout--------------------------------------------

<progressbar
Android:id= "@+id/total_pb_avage"
Style= "@android: Style/widget.progressbar.horizontal"
Android:layout_width= "Match_parent"
android:layout_height= "3.5DP"
android:layout_marginleft= "10DP"
android:layout_marginright= "15DP"
android:layout_margintop= "4DP"

android:max= "100"

Android:progress= "20"

android:progressdrawable= "@drawable/progress_bar_background"/>

Related properties are described:

Style is the style of the specified progress bar, provided by the system in the following ways:

Style= "@android: Style/widget.progressbar.small"/** small Circular progress bar */

Style= "@android: Style/widget.progressbar.small.inverse"/** small Circular progress bar */

Style= "@android: Style/widget.progressbar.inverse" /** medium Round progress bar * /

Style= "@android: Style/widget.progressbar.large" /** Large circular progress bar * /

Style= "@android: Style/widget.progressbar.large.inverse" /** Large circular progress bar * /

Style= "@android: Style/widget.progressbar.horizontal" /** Horizontal progress bar * /

Android:max= "" To specify the maximum value of the progress bar

Android:progress= "" To specify the current progress

Android:progressdrawable= "" is the key to today, to specify the image style, including the in-progress style, our custom style is mainly in this above the fuss:

----------------custom styles under Drawable file Progress_bar_background.xml------------------------

<layer-list xmlns:android= "Http://schemas.android.com/apk/res/android" >
<item android:id= "@android: Id/background" ><!-- normal Effects--
<shape>
<corners android:radius= "2dip"/><!--set the fillet radius -
<gradient<!--set the gradient effect -

Android:angle= "270"
Android:centercolor= "#e5e5e5"
android:centery= "2.0"
Android:endcolor= "#e5e5e5"
Android:startcolor= "#e5e5e5"/>
</shape>
</item>
<item android:id= "@android: Id/progress" ><!--effect in the rows -
<clip>
<shape>
<corners android:radius= "2dip"/>
<gradient
Android:angle= "270"
Android:centercolor= "#e12328"
android:centery= "2.0"
Android:endcolor= "#e12328"
Android:startcolor= "#e12328"/>
</shape>
</clip>
</item>
</layer-list>

--------------------code is simple-------------------------

Private ProgressBar Mpbar;

Mpbar=findviewbyid (R.id.total_pb_avage);

Mpbar.setprogress (XXX);//xxx is the value you want to display, the value part will show the red effect


Customizing the Android progress bar ProgressBar style

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.