Multi-style progressbar
Normal Circular progressbar
This type of progress bar indicates a running process, such as sending text messages and connecting to the network. It indicates that a process is being executed.
Generally, you only need to define it in the XML layout.
- <Progressbar Android: Id = "@ + ID/widget43"
- Android: layout_width = "wrap_content"
- Android: layout_height = "wrap_content"
- Android: layout_gravity = "center_vertical">
- </Progressbar>
CopyCode
In this case, if the style is not set, it is circular and the progress bar is always rotated.
Circular ssssbar of various styles
Super large circular progressbar
After setting a style attribute, the progressbar has a style. The style of the large progressbar is as follows:
- Style = "? Android: ATTR/progressbarstylelarge"
Copy code
The complete XML definition is:
- <Progressbar Android: Id = "@ + ID/widget196"
- Android: layout_width = "wrap_content"
- Android: layout_height = "wrap_content"
- Style = "? Android: ATTR/progressbarstylelarge ">
- </Progressbar>
Copy code
Small circular progressbar
09:04:58 upload
Download Attachment(1.21 KB)
The style of the small progressbar is:
- Style = "? Android: ATTR/progressbarstylesmall"
Copy code
Title circular progressbar
The style of the title progressbar is:
- Style = "? Android: ATTR/progressbarstylesmalltitle"
Copy code
The complete XML definition is:
- <Progressbar Android: Id = "@ + ID/widget110"
- Android: layout_width = "wrap_content"
- Android: layout_height = "wrap_content"
- Style = "? Android: ATTR/progressbarstylesmalltitle ">
- </Progressbar>
Copy code
Implementation in code:
- @ Override
- Protected void oncreate (bundle savedinstancestate ){
- // Todo auto-generated method stub
- Super. oncreate (savedinstancestate );
- Requestwindowfeature (window. feature_indeterminate_progress );
- // Special style of the Request window, which is set to an ambiguous progress Style
- Setcontentview (R. layout. Second );
- Setprogressbarindeterminatevisibility (true );
- // Set whether an ambiguous progress bar in the title bar can be displayed
- }
Copy code
Long progress bar
Long progress bar in Layout
① Layout in XML
- <Progressbar Android: Id = "@ + ID/progressbar_updown"
- Android: layout_width = "200dp"
- Android: layout_height = "wrap_content"
- Style = "? Android: ATTR/progressbarstylehorizontal"
- Android: layout_gravity = "center_vertical"
- Android: max = "100"
- Android: Progress = "50"
- Android: secondaryprogress = "70">
Copy code
Explanation:
② USE IN CODE
- Private progressbar myprogressbar;
- // Define progressbar
- Myprogressbar = (progressbar) findviewbyid (R. Id. progressbar_updown );
- // Progressbar obtains the id from XML
- Myprogressbar. incrementprogressby (5 );
- // Increase the progress value of progressbar by 5
- Myprogressbar. incrementprogressby (-5 );
- // The Progress value of progressbar is reduced by 5
- Myprogressbar. incrementsecondaryprogressby (5 );
- // The Progress value of the Second progress bar increases by 5
- Myprogressbar. incrementsecondaryprogressby (-5 );
- // The Progress value of the Second progress bar is reduced by 5
Copy code
Long progress bar in the page title
Code implementation:
① Set the window style features first
- Requestwindowfeature (window. feature_progress );
- // Request a window progress bar feature Style
- Setcontentview (R. layout. Main );
- Setprogressbarvisibility (true );
- // Set the progress bar to be visible
Copy code
② Set the progress value.
- Setprogress (myprogressbar. getprogress () * 100 );
- // Set a progress bar value in the title bar.
- Setsecondaryprogress (myprogressbar. getsecondaryprogress () * 100 );
- // Set a progress bar value next to the title bar
- // Progressbar. getsecondaryprogress () is used to obtain the progress value of other progress bars.
Copy code
Progressdialog
Circular progress bar in progressdialog
Progressdialog is generally used to indicate the progress of a system task or when the task is enabled.
Code implementation:
-
- Progressdialog mypdialog = new progressdialog (this );
-
- // Instantiate
- Mypdialog. setprogressstyle (progressdialog. style_spinner );
-
- // Set the progress bar style, circle style, and Rotation
-
- Mypdialog. settitle ("google ");
-
- // Set the progressdialog title
-
- Mypdialog. setmessage (getresources (). getstring (R. String. Second ));
-
- // Set progressdialog prompt information
-
- Mypdialog. seticon (R. drawable. Android );
-
- // Set the progressdialog title icon
-
- Mypdialog. setbutton ("google", this );
- // Set a button for progressdialog
-
- Mypdialog. setindeterminate (false );
-
- // Set whether the progress bar of progressdialog is clear
-
- Mypdialog. setcancelable (true );
-
- // Sets whether progressdialog can be canceled by pressing the return button.
-
- Mypdialog. Show ();
-
- // Display progressdialog
Copy code
Long progress bar in progressdialog
Code implementation:
- Progressdialog mypdialog = new progressdialog (this );
-
- // Instantiate
-
- Mypdialog. setprogressstyle (progressdialog. style_horizontal );
-
- // Set the progress bar style. The style is long and has a scale.
-
- Mypdialog. settitle ("Hell angry beast ");
-
- // Set the progressdialog title
-
- Mypdialog. setmessage (getresources (). getstring (R. String. Second ));
-
- // Set progressdialog prompt information
-
- Mypdialog. seticon (R. drawable. Android );
-
- // Set the progressdialog title icon
- Mypdialog. setprogress (59 );
-
- // Set the progress bar of progressdialog
-
- Mypdialog. setbutton ("Hell Dawn", this );
-
- // Set a button for progressdialog
-
- Mypdialog. setindeterminate (false );
-
- // Set whether the progress bar of progressdialog is clear
-
- Mypdialog. setcancelable (true );
-
- // Sets whether progressdialog can be canceled by pressing the return button.
-
- Mypdialog. Show ();
- // Display progressdialog
Copy code
Alertdialog. Builder
Circular progressbar in alertdialog
① Design a layout first. Later, as a view, add alertdialog. Builder
-
- <? XML version = "1.0" encoding = "UTF-8"?>
-
- <Linearlayout xmlns: Android = "http://schemas.android.com/apk/res/android"
-
- Android: layout_gravity = "center_horizontal"
-
- Android: layout_width = "wrap_content"
-
- Android: layout_height = "wrap_content">
-
- <Linearlayout Android: Id = "@ + ID/linearlayout01"
-
- Android: layout_width = "wrap_content"
- Android: layout_height = "wrap_content">
-
- </Linearlayout>
-
- <Progressbar Android: layout_gravity = "center_vertical | center_horizontal"
-
- Android: layout_height = "wrap_content"
-
- Android: Progress = "57"
-
- Android: Id = "@ + ID/myview_progressbar2"
-
- Android: layout_width = "wrap_content">
-
- </Progressbar>
-
- </Linearlayout>
Copy code
② Code Luo
- Private alertdialog. Builder Alterd, alterd2;
- // Define dialog box
- Private layoutinflater;
- // Define the layout Filter
- Private linearlayout mylayout;
- // Define the Layout
- Layoutinflater2 = (layoutinflater) getsystemservice (this. layout_inflater_service );
- // Obtain the layout filtering service of the system
- Mylayout2 = (linearlayout) layoutinflater2.inflate (R. layout. roundprogress, null );
- // Get the layout designed in advance
- Alterd2.settitle (getresources (). getstring (R. String. roundo ));
- // Set the dialog box title
- Alterd2.seticon (R. drawable. Ma );
- // Set the dialog box icon
- Alterd2.setmessage (getresources (). getstring (R. String. addview ));
- // Prompt information in the Setting Dialog Box
- Alterd2.setview (mylayout2 );
- // View in the Setting Dialog Box
- Alterd2.show ();
- // Display the dialog box
Copy code
Long progressbar in alertdialog (controllable)
① Design a layout first. Later, as a view, add alertdialog. Builder
-
- <? XML version = "1.0" encoding = "UTF-8"?>
-
- <Linearlayout xmlns: Android = "http://schemas.android.com/apk/res/android"
-
- Android: layout_gravity = "center_horizontal"
-
- Android: layout_width = "wrap_content"
-
- Android: layout_height = "wrap_content">
-
- <Button
-
- Android: layout_height = "wrap_content"
-
- Android: text = "-"
-
- Android: layout_width = "50dp"
-
- Android: Id = "@ + ID/myview_bt_down">
-
- </Button>
-
- <Progressbar
-
- Android: layout_gravity = "center_vertical"
-
- Android: layout_height = "wrap_content"
- Style = "? Android: ATTR/progressbarstylehorizontal"
-
- Android: Id = "@ + ID/myview_progressbar"
-
- Android: Progress = "57"
-
- Android: layout_width = "178dp">
-
- </Progressbar>
-
- <Button Android: layout_height = "wrap_content"
-
- Android: text = "+"
-
- Android: layout_width = "50dp"
-
- Android: Id = "@ + ID/myview_bt_up">
-
- </Button>
-
- </Linearlayout>
Copy code
② Code Luo
-
- Private alertdialog. Builder Alterd, alterd2;
-
- // Define dialog box
-
- Private layoutinflater;
-
- // Define the layout Filter
- Private linearlayout mylayout;
-
- // Define the Layout
-
- Layoutinflater = (layoutinflater) getsystemservice (this. layout_inflater_service );
-
- // Obtain the layout filtering service of the system
-
- Mylayout = (linearlayout) layoutinflater. Inflate (R. layout. myview, null );
-
- // Get the layout designed in advance
-
-
- Myup = (button) mylayout. findviewbyid (R. Id. myview_bt_up );
-
- Mydown = (button) mylayout. findviewbyid (R. Id. myview_bt_down );
-
- Mypro = (progressbar) mylayout. findviewbyid (R. Id. myview_progressbar );
-
- // Use mylayout. findviewbyid to obtain widget control elements in the Custom View
-
-
- Myup. setonclicklistener (this );
-
- // Set the button listener in the view dialog box
-
- Mydown. setonclicklistener (this );
-
- // Set the button listener in the view dialog box
-
- Mypro. setprogress (TAG );
-
- // Set a tag as the progress Value
- Alterd. settitle (getresources (). getstring (R. String. recto ));
-
- // Set the dialog box title
-
- Alterd. seticon (R. drawable. MB );
-
- // Set the dialog box icon
-
- Alterd. setmessage (getresources (). getstring (R. String. addview ));
-
- // Prompt information in the Setting Dialog Box
-
- Alterd. setview (mylayout );
-
- // View added in the Setting Dialog Box
-
- Alterd. setpositivebutton ("OK", new dialoginterface. onclicklistener (){
-
- @ Override
-
- Public void onclick (dialoginterface dialog, int which ){
-
- // Todo auto-generated method stub
-
- Myprogressbar. Tag = mypro. getprogress ();
-
- }});
-
- // Set the dialog box button and the event listener of the button
-
- Alterd. Show ();
-
- // Display the dialog box
Copy code
③ Button event of progress bar value
-
- Myup. setonclicklistener (this );
-
- // Set the button listener in the view dialog box
-
- Mydown. setonclicklistener (this );
-
- // Set the button listener in the view dialog box
-
- Corresponding code:
-
- @ Override
-
- Public void onclick (View button ){
-
- // Todo auto-generated method stub
-
- Switchupordown (button );
-
- }
-
-
- Private void switchupordown (View button ){
-
- Switch (button. GETID ()){
-
- Case R. Id. myview_bt_up :{
- Mypro. incrementprogressby (1 );
-
- }
-
- Break;
-
- Case R. Id. myview_bt_down :{
-
- Mypro. incrementprogressby (-1 );
-
- }
-
- Break;
-
- Default:
-
- Break;
-
- }
-
- }