Android control ProgressBar

Source: Internet
Author: User


1. ProgressBar with progress bar
[Html]
Protected void onCreate (Bundle savedInstanceState ){
Super. onCreate (savedInstanceState );
 
// Request the progress bar to be shown in the title
RequestWindowFeature (Window. FEATURE_PROGRESS );
SetContentView (R. layout. progressbar_1 );
SetProgressBarVisibility (true); // set the ProgressBar to be visible in the title.

Final ProgressBar progressHorizontal = (ProgressBar) findViewById (R. id. progress_horizontal );

SetProgress (progressHorizontal. getProgress () * 100); // set the progress for ProgressBar in title
SetSecondaryProgress (progressHorizontal. getSecondaryProgress () * 100); // set the secondary progress for the ProgressBar In the title

Button button = (Button) findViewById (R. id. increase); // The first-level progress increases progressively
Button. setOnClickListener (new Button. OnClickListener (){
Public void onClick (View v ){
ProgressHorizontal. incrementProgressBy (1 );
// Title progress is in range 0 .. 10000
SetProgress (100 * progressHorizontal. getProgress (); // set the progress for ProgressBar in title
}
});
 
Button = (Button) findViewById (R. id. decrease); // The first-level progress decreases.
Button. setOnClickListener (new Button. OnClickListener (){
Public void onClick (View v ){
ProgressHorizontal. incrementProgressBy (-1 );
// Title progress is in range 0 .. 10000
SetProgress (100 * progressHorizontal. getProgress (); // set the progress for ProgressBar in title
}
});
 
Button = (Button) findViewById (R. id. increase_secondary); // The second-level progress increases progressively
Button. setOnClickListener (new Button. OnClickListener (){
Public void onClick (View v ){
ProgressHorizontal. incrementSecondaryProgressBy (1 );
// Title progress is in range 0 .. 10000
SetSecondaryProgress (100 * progressHorizontal. getSecondaryProgress ());
}
});
 
Button = (Button) findViewById (R. id. decrease_secondary); // The secondary progress decreases.
Button. setOnClickListener (new Button. OnClickListener (){
Public void onClick (View v ){
ProgressHorizontal. incrementSecondaryProgressBy (-1 );
// Title progress is in range 0 .. 10000
SetSecondaryProgress (100 * progressHorizontal. getSecondaryProgress ());
}
});

}
Configuration file:
[Html]
<ProgressBar android: id = "@ + id/progress_horizontal"
Style = "? Android: attr/progressBarStyleHorizontal"
Android: layout_width = "200dip"
Android: layout_height = "wrap_content"
Android: max = "100"
Android: progress = "50"
Android: secondaryProgress = "75"/>

 

:

 

2. progress bar of the circled Style
[Html]
<LinearLayout xmlns: android = "http://schemas.android.com/apk/res/android"
Android: layout_width = "match_parent"
Android: layout_height = "wrap_content"
Android: orientation = "vertical">
 
<ProgressBar
Android: id = "@ + android: id/progress_large"
Style = "? Android: attr/progressBarStyleLarge "// large style
Android: layout_width = "wrap_content"
Android: layout_height = "wrap_content"/>
 
<ProgressBar // default
Android: id = "@ + android: id/progress"
Android: layout_width = "wrap_content"
Android: layout_height = "wrap_content"/>
 
<ProgressBar
Android: id = "@ + android: id/progress_small" // small Style
Style = "? Android: attr/progressBarStyleSmall"
Android: layout_width = "wrap_content"
Android: layout_height = "wrap_content"/>
 
<ProgressBar // subtitle Style
Android: id = "@ + android: id/progress_small_title"
Style = "? Android: attr/progressBarStyleSmallTitle"
Android: layout_width = "wrap_content"
Android: layout_height = "wrap_content"/>
 
</LinearLayout>

Java code:
[Html]
Protected void onCreate (Bundle savedInstanceState ){
Super. onCreate (savedInstanceState );
 
// Request for the progress bar to be shown in the title
RequestWindowFeature (Window. FEATURE _ <span style = "color: # ff0000;"> INDETERMINATE </span> _ PROGRESS );

SetContentView (R. layout. progressbar_2 );

// Make sure the progress bar is visible
SetProgressBarVisibility (true );
}

Effect:


3. Dialog style ProgressBar
[Html]
Private static final int DIALOG1_KEY = 0;
Private static final int DIALOG2_KEY = 1;
 
 
@ Override
Protected void onCreate (Bundle savedInstanceState ){
Super. onCreate (savedInstanceState );
 
SetContentView (R. layout. progressbar_3 );
 
Button button = (Button) findViewById (R. id. showIndeterminate );
Button. setOnClickListener (new View. OnClickListener (){
Public void onClick (View v ){
ShowDialog (DIALOG1_KEY );
}
});
 
Button = (Button) findViewById (R. id. showIndeterminateNoTitle );
Button. setOnClickListener (new View. OnClickListener (){
Public void onClick (View v ){
ShowDialog (DIALOG2_KEY );
}
});
}
 
@ Override
Protected Dialog onCreateDialog (int id ){
Switch (id ){
Case DIALOG1_KEY :{
ProgressDialog dialog = new ProgressDialog (this );
Dialog. setTitle ("Indeterminate ");
Dialog. setMessage ("Please wait while loading ...");
Dialog. set <span style = "color: # ff0000;"> Indeterminate </span> (true); // sets the effect of the circle.
Dialog. setCancelable (true );
Return dialog;
}
Case DIALOG2_KEY :{
ProgressDialog dialog = new ProgressDialog (this );
Dialog. setMessage ("Please wait while loading ...");
Dialog. set <span style = "color: # ff0000;"> Indeterminate </span> (true); // sets the effect of the circle.
Dialog. setCancelable (true );
Return dialog;
}
}
Return null;
}

Effect:


4. ssbar In the title circle
[Java]
Private boolean mToggleIndeterminate = false;
 
@ Override
Protected void onCreate (Bundle savedInstanceState ){
Super. onCreate (savedInstanceState );
 
// Request progress bar
RequestWindowFeature (Window. FEATURE _ <span style = "color: # ff0000;"> INDETERMINATE </span> _ PROGRESS); // ssbar of the circled sample
SetContentView (R. layout. progressbar_4 );
SetProgressBarIndeterminateVisibility (mToggleIndeterminate); // visible

Button button = (Button) findViewById (R. id. toggle );
Button. setOnClickListener (new Button. OnClickListener (){
Public void onClick (View v ){
MToggleIndeterminate =! MToggleIndeterminate; // if it is false, set it to true. If it is true, set it to false.
SetProgressBarIndeterminateVisibility (mToggleIndeterminate); // visible
}
});
}



Author: johnny901114

Related Article

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.