Transverse ProgressBar.
Create Drawable folder under Res, new file Drawable/progressbar_color.xml
<?xml version= "1.0" encoding= "Utf-8"? ><layer-list xmlns:android= "http://schemas.android.com/apk/res/ Android > <!--background gradient is a gradient, corners defines rounded corners--<item android:id= "@android: Id/background" > <shape> <corners android:radius= "10DP"/> <solid android:color= "#ffffff"/> </shape> </item> <!--second progress bar color--<item android:id= "@android: Id/secondaryprogress" > <clip> <shape> <corners android:radius= "10dip"/> <gra Dient android:angle= "90.0" android:centercolor= "#ac6079" Android: centery= "0.45" android:endcolor= "#6c213a" android:startcolor= "#e71a5e"/> </shape> </clip> </item> <!--progress Bar--<item android:id= "@android: Id/progres S "> <clip> <shape> <corners android:radius= "10dip"/> <solid android:color= "#FF8080"/ > </shape> </clip> </item> </layer-list>
Then refer to it in the layout.
Activity_main.xml
<progressbar android:id= "@+id/my_progress" android:layout_width= "match_parent" android:layout_ height= "12DP" android:max= "android:progress=" " android:secondaryprogress=" "style=" ? Android:attr/progressbarstylehorizontal " android:progressdrawable=" @drawable/progressbar_color "/>
Round ProgressBar.
Customizing the ProgressBar of a circle
:
The style of round ProgressBar mainly has the following several, we here take Progressbarstylelarge as an example to modify the style, other similar.
<progressbar android:layout_width= "wrap_content" android:layout_height= "wrap_content" style= "? Android: Attr/progressbarstylelarge "/>
First look at the source of style= "? Android:attr/progressbarstylelarge", in \frameworks\base\core\res\res\values\styles.xml
<style name= "Widget.ProgressBar.Large" > <item name= "android:indeterminatedrawable" > @android:d rawable/ progress_large_white</item> <item name= "android:minwidth" >76dip</item> <item name= "Android: MaxWidth ">76dip</item> <item name=" android:minheight ">76dip</item> <item name=" Android: MaxHeight ">76dip</item></style>
See this line <item name= "android:indeterminatedrawable" > @android:d rawable/progress_large_white</item> have wood there, Let's take a look at its source code, in \frameworks\base\core\res\res\drawable\progress_large_white.xml
<rotate xmlns:android= "http://schemas.android.com/apk/res/android" android:drawable= "@drawable/spinner_ white_76 " android:pivotx=" 50% " android:pivoty=" 50% " android:fromdegrees=" 0 " android:todegrees= "/>"
See this line android:drawable= "@drawable/spinner_white_76" We understand, originally it put a picture here, to rotate.
Next I define my own Progressbarstyle:
First we look for a picture to join our project (such as the beginning of the film), and then create a new Progress_large.xml file under Drawable
<?xml version= "1.0" encoding= "Utf-8"? ><rotate xmlns:android= "Http://schemas.android.com/apk/res/android" android:drawable= "@drawable/progress_large" android:fromdegrees= "0" android:pivotx= "50% " Android:pivoty= "50%" android:todegrees= "/>"
Defining Myprogressbarstylelarge in \value\style.xml
<style name= "Myprogressbarstylelarge" > <item name= "android:indeterminatedrawable" > @drawable/progress_ large</item> <item name= "android:minwidth" >76dip</item> <item name= "Android:maxwidth" > 76dip</item> <item name= "android:minheight" >76dip</item> <item name= "Android:maxheight" > 76dip</item></style>
Finally, we use our own definition of style,android:indeterminateduration= "700" in ProgressBar to specify the speed of the picture rotation, so that we can define the style of the ProgressBar according to our own needs.
<progressbar style= "@style/myprogressbarstylelarge" android:layout_width= "Wrap_content" android:layout_height= "Wrap_content" android:indeterminateduration= "/>"
above is a picture filled with android:indeterminatedrawable, we can also define an animation or custom color to implement, as the image of the use of:
The definition res/anim/progress_large_loading.xml is as follows:
<?xml version= "1.0" encoding= "UTF-8"?> <animation-list android:oneshot= "false" xmlns:android= " Http://schemas.android.com/apk/res/android "> <item android:duration=" android:drawable= "@drawable/ Loading_1 "/> <item android:duration=" android:drawable= "@drawable/loading_2"/> <item android:duration= "android:drawable=" @drawable/loading_3 "/> <item android:duration=" Android: drawable= "@drawable/loading_4"/> <item android:duration= "android:drawable=" @drawable/loading_5 "/ > <item android:duration= "android:drawable=" @drawable/loading_6 "/></animation-list>
Introduce <item name= "android:indeterminatedrawable" > @anim/progress_large_loading</item> in our defined style
The definition res/drawable/progress_large_shape.xml is as follows:
<?xml version= "1.0" encoding= "Utf-8"?> <rotate xmlns:android= "http://schemas.android.com/apk/res/ Android " android:fromdegrees=" 0 " android:pivotx=" 50% " android:pivoty=" 50% " android:todegrees=" "> <shape android:innerradiusratio=" 3 " android:shape=" Ring " android:thicknessratio = "8" android:uselevel= "false" > <gradient android:centercolor= "#FFFFFF" Andro id:centery= "0.50" android:endcolor= "#1E90FF" android:startcolor= "#000000" android:type= "s Weep " android:uselevel=" false "/> </shape> </rotate>
Introduced in our defined style
<item name= "android:indeterminatedrawable" > @drawable/progress_large_shape</item>
Android two custom ProgressBar