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