1. ProgressDialog
ProgressDialog and ProgressBar dynamically display a loading icon in the UI to display the running status.
ProgressDialog is inherited from Android. app. the Interactive dialog window designed by ProgressDialog. during use, you must create a ProgressDialog object. A "dialog box" will pop up during running as a reminder, in this case, the background of the application loses focus (that is, the UI component cannot be operated at this time), and the control is not handed over to the application until the process ends. If you do not want the background to lose focus in the Activity, if you want to prompt the User that a background program is in a busy stage, the ProgressBar will be used.
Copy codeThe Code is as follows: ProgressDialog mProgressDialog = new ProgressDialog (TestProgerssDialogActivity. this );
// Set the mProgressDialog Style
MProgressDialog. setProgress (ProgressDialog. STYLE_SPINNER); // Circular
MProgressDialog. setProgress (ProgressDialog. STYLE_HORIZONTAL); // horizontal
// Set the mProgressDialog title
MProgressDialog. setTitle ("prompt ");
// Set the mProgressDialog prompt
MProgressDialog. setMessage ("this is a circular progress bar dialog box ");
// Set the mProgressDialog progress bar icon
MProgressDialog. setIcon (R. drawable. flag );
// Set whether the progress bar of mProgressDialog is unclear
// When not rolling, the current value moves between the minimum and maximum values. Generally, it serves as a prompt for tasks that cannot determine the operation time, you can set the current progress value based on your progress.
MProgressDialog. setIndeterminate (false );
// MProgressDialog. setProgress (m_count ++ );
// Can I press the rollback key to cancel the operation?
MProgressDialog. setCancelable (true );
// Set a Button for mProgressDialog
MProgressDialog. setButton ("OK", new DialogInterface. OnClickListener ()
{
@ Override
Public void onClick (DialogInterface dialog, int which)
{
Dialog. cancel ();
}
});
// Display mProgressDialogmProgressDialog. show ();
Copy codeThe Code is as follows: mProgressDialog. setOnCancelListener (new DialogInterface. OnCancelListener (){
@ Override
Public void onCancel (DialogInterface dialog ){
// TODO Auto-generated method stub
MProgressDialog. hide ();
Webview. stopLoading ();
}
});
When ProgressDialog is enabled, When you click back, ProgressDialog is canceled first. The above code can listen to the progress bar cancellation event (that is, click Back to cancel ProgressDialog ), at this time, you can cancel the background operations here.
Ii. ProgressBar
Important XML attributes
Android: progressBarStyle: Default progress bar style
Android: progressBarStyleHorizontal: horizontal style
Important Methods
GetMax (): Maximum range of the returned progress bar
GetProgress (): returns the progress
GetSecondaryProgress (): returns the secondary progress
IncrementProgressBy (int diff): Specifies the increase progress.
IsIndeterminate (): indicates whether the progress bar is in uncertain mode.
SetIndeterminate (boolean indeterminate): sets the uncertain mode.
SetVisibility (int v): sets whether the progress bar is visible.
Important events
OnSizeChanged (int w, int h, int oldw, int oldh): this event is triggered when the progress value changes.
Copy codeThe Code is as follows: <? Xml version = "1.0" encoding = "UTF-8"?>
<LinearLayout xmlns: android = "http://schemas.android.com/apk/res/android"
Android: orientation = "vertical"
Android: layout_width = "fill_parent"
Android: layout_height = "fill_parent">
<TextView
Android: layout_width = "fill_parent"
Android: layout_height = "wrap_content"
Android: text = "Welcome to blog"/>
<ProgressBar
Android: id = "@ + id/rectangleProgressBar"
Style = "? Android: attr/progressBarStyleHorizontal "mce_style = "? Android: attr/progressBarStyleHorizontal"
Android: layout_width = "fill_parent"
Android: layout_height = "wrap_content"
Android: visibility = "gone"
/>
<ProgressBar
Android: id = "@ + id/circleProgressBar"
Style = "? Android: attr/progressBarStyleLarge "mce_style = "? Android: attr/progressBarStyleLarge"
Android: layout_width = "wrap_content"
Android: layout_height = "wrap_content"
Android: visibility = "gone"
/>
<Button android: id = "@ + id/button"
Android: text = "Show ProgressBar"
Android: layout_width = "wrap_content"
Android: layout_height = "wrap_content"
/>
</LinearLayout>