Summary of style settings for Android progressbar

Source: Internet
Author: User

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.

    1. <Progressbar Android: Id = "@ + ID/widget43"
    2. Android: layout_width = "wrap_content"
    3. Android: layout_height = "wrap_content"
    4. Android: layout_gravity = "center_vertical">
    5. </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:

    1. Style = "? Android: ATTR/progressbarstylelarge"

Copy code

The complete XML definition is:

    1. <Progressbar Android: Id = "@ + ID/widget196"
    2. Android: layout_width = "wrap_content"
    3. Android: layout_height = "wrap_content"
    4. Style = "? Android: ATTR/progressbarstylelarge ">
    5. </Progressbar>

Copy code

Small circular progressbar

09:04:58 upload

Download Attachment(1.21 KB) 


The style of the small progressbar is:

    1. Style = "? Android: ATTR/progressbarstylesmall"

Copy code

Title circular progressbar

 

 

The style of the title progressbar is:

    1. Style = "? Android: ATTR/progressbarstylesmalltitle"

Copy code

The complete XML definition is:

    1. <Progressbar Android: Id = "@ + ID/widget110"
    2. Android: layout_width = "wrap_content"
    3. Android: layout_height = "wrap_content"
    4. Style = "? Android: ATTR/progressbarstylesmalltitle ">
    5. </Progressbar>

Copy code

Implementation in code:

    1. @ Override
    2. Protected void oncreate (bundle savedinstancestate ){
    3. // Todo auto-generated method stub
    4. Super. oncreate (savedinstancestate );
    5. Requestwindowfeature (window. feature_indeterminate_progress );
    6. // Special style of the Request window, which is set to an ambiguous progress Style
    7. Setcontentview (R. layout. Second );
    8. Setprogressbarindeterminatevisibility (true );
    9. // Set whether an ambiguous progress bar in the title bar can be displayed
    10. }

Copy code

Long progress bar

Long progress bar in Layout

 

① Layout in XML

    1. <Progressbar Android: Id = "@ + ID/progressbar_updown"
    2. Android: layout_width = "200dp"
    3. Android: layout_height = "wrap_content"
    4. Style = "? Android: ATTR/progressbarstylehorizontal"
    5. Android: layout_gravity = "center_vertical"
    6. Android: max = "100"
    7. Android: Progress = "50"
    8. Android: secondaryprogress = "70">

Copy code

Explanation:

② USE IN CODE

    1. Private progressbar myprogressbar;
    2. // Define progressbar
    3. Myprogressbar = (progressbar) findviewbyid (R. Id. progressbar_updown );
    4. // Progressbar obtains the id from XML
    5. Myprogressbar. incrementprogressby (5 );
    6. // Increase the progress value of progressbar by 5
    7. Myprogressbar. incrementprogressby (-5 );
    8. // The Progress value of progressbar is reduced by 5
    9. Myprogressbar. incrementsecondaryprogressby (5 );
    10. // The Progress value of the Second progress bar increases by 5
    11. Myprogressbar. incrementsecondaryprogressby (-5 );
    12. // 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

    1. Requestwindowfeature (window. feature_progress );
    2. // Request a window progress bar feature Style
    3. Setcontentview (R. layout. Main );
    4. Setprogressbarvisibility (true );
    5. // Set the progress bar to be visible

Copy code

② Set the progress value.

    1. Setprogress (myprogressbar. getprogress () * 100 );
    2. // Set a progress bar value in the title bar.
    3. Setsecondaryprogress (myprogressbar. getsecondaryprogress () * 100 );
    4. // Set a progress bar value next to the title bar
    5. // 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:

  1. Progressdialog mypdialog = new progressdialog (this );
  2. // Instantiate
  3. Mypdialog. setprogressstyle (progressdialog. style_spinner );
  4. // Set the progress bar style, circle style, and Rotation
  5. Mypdialog. settitle ("google ");
  6. // Set the progressdialog title
  7. Mypdialog. setmessage (getresources (). getstring (R. String. Second ));
  8. // Set progressdialog prompt information
  9. Mypdialog. seticon (R. drawable. Android );
  10. // Set the progressdialog title icon
  11. Mypdialog. setbutton ("google", this );
  12. // Set a button for progressdialog
  13. Mypdialog. setindeterminate (false );
  14. // Set whether the progress bar of progressdialog is clear
  15. Mypdialog. setcancelable (true );
  16. // Sets whether progressdialog can be canceled by pressing the return button.
  17. Mypdialog. Show ();
  18. // Display progressdialog

Copy code

Long progress bar in progressdialog





Code implementation:

  1. Progressdialog mypdialog = new progressdialog (this );
  2. // Instantiate
  3. Mypdialog. setprogressstyle (progressdialog. style_horizontal );
  4. // Set the progress bar style. The style is long and has a scale.
  5. Mypdialog. settitle ("Hell angry beast ");
  6. // Set the progressdialog title
  7. Mypdialog. setmessage (getresources (). getstring (R. String. Second ));
  8. // Set progressdialog prompt information
  9. Mypdialog. seticon (R. drawable. Android );
  10. // Set the progressdialog title icon
  11. Mypdialog. setprogress (59 );
  12. // Set the progress bar of progressdialog
  13. Mypdialog. setbutton ("Hell Dawn", this );
  14. // Set a button for progressdialog
  15. Mypdialog. setindeterminate (false );
  16. // Set whether the progress bar of progressdialog is clear
  17. Mypdialog. setcancelable (true );
  18. // Sets whether progressdialog can be canceled by pressing the return button.
  19. Mypdialog. Show ();
  20. // Display progressdialog

Copy code



Alertdialog. Builder

Circular progressbar in alertdialog





① Design a layout first. Later, as a view, add alertdialog. Builder

  1. <? XML version = "1.0" encoding = "UTF-8"?>
  2. <Linearlayout xmlns: Android = "http://schemas.android.com/apk/res/android"
  3. Android: layout_gravity = "center_horizontal"
  4. Android: layout_width = "wrap_content"
  5. Android: layout_height = "wrap_content">
  6. <Linearlayout Android: Id = "@ + ID/linearlayout01"
  7. Android: layout_width = "wrap_content"
  8. Android: layout_height = "wrap_content">
  9. </Linearlayout>
  10. <Progressbar Android: layout_gravity = "center_vertical | center_horizontal"
  11. Android: layout_height = "wrap_content"
  12. Android: Progress = "57"
  13. Android: Id = "@ + ID/myview_progressbar2"
  14. Android: layout_width = "wrap_content">
  15. </Progressbar>
  16. </Linearlayout>

Copy code

② Code Luo

    1. Private alertdialog. Builder Alterd, alterd2;
    2. // Define dialog box
    3. Private layoutinflater;
    4. // Define the layout Filter
    5. Private linearlayout mylayout;
    6. // Define the Layout
    7. Layoutinflater2 = (layoutinflater) getsystemservice (this. layout_inflater_service );
    8. // Obtain the layout filtering service of the system
    9. Mylayout2 = (linearlayout) layoutinflater2.inflate (R. layout. roundprogress, null );
    10. // Get the layout designed in advance
    11. Alterd2.settitle (getresources (). getstring (R. String. roundo ));
    12. // Set the dialog box title
    13. Alterd2.seticon (R. drawable. Ma );
    14. // Set the dialog box icon
    15. Alterd2.setmessage (getresources (). getstring (R. String. addview ));
    16. // Prompt information in the Setting Dialog Box
    17. Alterd2.setview (mylayout2 );
    18. // View in the Setting Dialog Box
    19. Alterd2.show ();
    20. // Display the dialog box

Copy code

Long progressbar in alertdialog (controllable)

① Design a layout first. Later, as a view, add alertdialog. Builder

  1. <? XML version = "1.0" encoding = "UTF-8"?>
  2. <Linearlayout xmlns: Android = "http://schemas.android.com/apk/res/android"
  3. Android: layout_gravity = "center_horizontal"
  4. Android: layout_width = "wrap_content"
  5. Android: layout_height = "wrap_content">
  6. <Button
  7. Android: layout_height = "wrap_content"
  8. Android: text = "-"
  9. Android: layout_width = "50dp"
  10. Android: Id = "@ + ID/myview_bt_down">
  11. </Button>
  12. <Progressbar
  13. Android: layout_gravity = "center_vertical"
  14. Android: layout_height = "wrap_content"
  15. Style = "? Android: ATTR/progressbarstylehorizontal"
  16. Android: Id = "@ + ID/myview_progressbar"
  17. Android: Progress = "57"
  18. Android: layout_width = "178dp">
  19. </Progressbar>
  20. <Button Android: layout_height = "wrap_content"
  21. Android: text = "+"
  22. Android: layout_width = "50dp"
  23. Android: Id = "@ + ID/myview_bt_up">
  24. </Button>
  25. </Linearlayout>

Copy code

② Code Luo

  1. Private alertdialog. Builder Alterd, alterd2;
  2. // Define dialog box
  3. Private layoutinflater;
  4. // Define the layout Filter
  5. Private linearlayout mylayout;
  6. // Define the Layout
  7. Layoutinflater = (layoutinflater) getsystemservice (this. layout_inflater_service );
  8. // Obtain the layout filtering service of the system
  9. Mylayout = (linearlayout) layoutinflater. Inflate (R. layout. myview, null );
  10. // Get the layout designed in advance
  11. Myup = (button) mylayout. findviewbyid (R. Id. myview_bt_up );
  12. Mydown = (button) mylayout. findviewbyid (R. Id. myview_bt_down );
  13. Mypro = (progressbar) mylayout. findviewbyid (R. Id. myview_progressbar );
  14. // Use mylayout. findviewbyid to obtain widget control elements in the Custom View
  15. Myup. setonclicklistener (this );
  16. // Set the button listener in the view dialog box
  17. Mydown. setonclicklistener (this );
  18. // Set the button listener in the view dialog box
  19. Mypro. setprogress (TAG );
  20. // Set a tag as the progress Value
  21. Alterd. settitle (getresources (). getstring (R. String. recto ));
  22. // Set the dialog box title
  23. Alterd. seticon (R. drawable. MB );
  24. // Set the dialog box icon
  25. Alterd. setmessage (getresources (). getstring (R. String. addview ));
  26. // Prompt information in the Setting Dialog Box
  27. Alterd. setview (mylayout );
  28. // View added in the Setting Dialog Box
  29. Alterd. setpositivebutton ("OK", new dialoginterface. onclicklistener (){
  30. @ Override
  31. Public void onclick (dialoginterface dialog, int which ){
  32. // Todo auto-generated method stub
  33. Myprogressbar. Tag = mypro. getprogress ();
  34. }});
  35. // Set the dialog box button and the event listener of the button
  36. Alterd. Show ();
  37. // Display the dialog box

Copy code

③ Button event of progress bar value

  1. Myup. setonclicklistener (this );
  2. // Set the button listener in the view dialog box
  3. Mydown. setonclicklistener (this );
  4. // Set the button listener in the view dialog box
  5. Corresponding code:
  6. @ Override
  7. Public void onclick (View button ){
  8. // Todo auto-generated method stub
  9. Switchupordown (button );
  10. }
  11. Private void switchupordown (View button ){
  12. Switch (button. GETID ()){
  13. Case R. Id. myview_bt_up :{
  14. Mypro. incrementprogressby (1 );
  15. }
  16. Break;
  17. Case R. Id. myview_bt_down :{
  18. Mypro. incrementprogressby (-1 );
  19. }
  20. Break;
  21. Default:
  22. Break;
  23. }
  24. }
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.