When an applicationProgramIf there is no information on the front-end interface during execution in the background, the user will not know whether the application is being executed or how the execution progresses, at this time, it is necessary to use the progress bar to prompt the execution of the background application.
The Android system provides two types of progress bars: A long progress bar (progressbarstylehorizontal) and a circular progress bar. The circular progress bar can be divided into three types: progressbarstylelarge, medium (default), and small (progressbarstylesmall. The specific progress bar style 1 is shown.
Figure 1 progress bar style
1. XML Attribute of the progress bar
How to specify the display style of the progress bar? This can be set through the style attribute in the XML Attribute. The specific implementation method is as follows:
1 <Progressbar2Android: layout_width= "Wrap_content"3 Android: layout_height= "Wrap_content"4 Style= "@ Android: style/widget. progressbar. Small. Inverse"> </Progressbar>
Pass the aboveCodeTo display a small circular progress bar. You can set the following attribute values for the style attribute to display medium, large, and horizontal progress bars.
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-sized circular 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
The difference between the style attribute with the inverse parameter and the style attribute without the inverse parameter is that when the background color of the interface where the progress bar control is located is white, the style attribute with the inverse parameter must be used, otherwise, the progress bar is invisible.
XML Attribute 2 of the progress bar.
Figure 2 XML attributes of the progress bar
Android: Max [int] is used to set the maximum scale of the horizontal progress bar; Android: progress [int] is used to set the current progress value of the progress bar; Android: secondaryprogress [int] is used to set the Second Progress value of the progress bar (for video buffering and so on ).
2. Title Bar progress display
Progress bars are useful. For example, when a program loads resources, you can prompt the user to wait. These progress bars only represent the execution of a certain part of the application, how can we display the execution of the entire application? This can be achieved by displaying a progress bar in the application title bar.
To display the progress of the title bar, you only need to set the display style of the window as follows:
1 /* 2 * Function: oncreate 3 * Author: blog Park-still indifferent 4 */ 5 Public Void Oncreate (bundle savedinstancestate ){ 6 Super . Oncreate (savedinstancestate ); 7 Requestwindowfeature (window. feature_progress ); // Progress indicator Function 8 Requestwindowfeature (window. feature_indeterminate_progress ); // Uncertain progress 9 Setcontentview (R. layout. activity_main ); // Load layout files 10 Setprogressbarindeterminatevisibility ( True ); // Progress bar showing uncertain progress 11 }
The effect 3 after running is shown in.
Figure 3 title bar progress bar
It can be seen that there is a gray progress bar on the title bar, and a small circular progress bar on the right. In addition, there are other style title bar, specific can refer to the blog: requestwindowfeature detailed use (http://zhanhao.iteye.com/blog/1174914 ).