Android app Development (eight)----------------progress bar for common components (cont.)

Source: Internet
Author: User

When you can't hold on, you can say to yourself, "I'm tired", but don't say "I can't" to myself.


There are many kinds of progress bars: Dialog progress bar, title bar progress bar, horizontal progress bar

First, the dialog box progress bar

(1) Overlay the activity's Oncreatedialog () method and create a dialog box in it

(2) Call the activity's ShowDialog () method to display the Progress Bar dialog box

Second, the title bar progress bar

(1) Call the activity's Requestwindowfeature () method to get the progress bar

(2) Call the activity's setprogressbarindeterminatevisibility () method to display the progress bar

Third, horizontal progress bar

(1) Life ProgressBar in Layout files

(2) Obtaining ProgressBar instances in activity

(3) Call ProgressBar's Incrementprogressby () method to increase or decrease the progress


1. Engineering Catalogue


2, Test_progressbar_activity.java

Package Com.example.teat_progressbar;import Android.os.bundle;import Android.app.activity;import Android.app.dialog;import Android.app.progressdialog;import Android.view.menu;import Android.view.View;import Android.view.view.onclicklistener;import Android.view.window;import Android.widget.button;import Android.widget.progressbar;public class Test_progressbar_activity extends Activity {private Button MyButton, XIANSHIBTN, Yincangbtn, increasebtn, decreasebtn; ProgressBar myprogressbar; @Overrideprotected void OnCreate (Bundle savedinstancestate) {super.oncreate ( savedinstancestate);//The following request: Must be in front of Setcontentview () requestwindowfeature (window.feature_indeterminate_progress); Setcontentview (R.layout.test_ _progress_bar) MyButton = (Button) Findviewbyid (R.id.button01); Mybutton.setonclicklistener (new Onclicklistener () {@ overridepublic void OnClick (View arg0) {//TODO auto-generated method Stubshowdialog (0);}}); xianshibtn = (Button) Findviewbyid (R.id.xianshibutton); yincangbtn = (Button) FindvieWbyid (R.id.yincangbutton); Xianshibtn.setonclicklistener (new Onclicklistener () {@Overridepublic void OnClick (View ARG0) {//TODO auto-generated method Stubsetprogressbarindeterminatevisibility (True);}}); Yincangbtn.setonclicklistener (New Onclicklistener () {@Overridepublic void OnClick (View arg0) {//TODO auto-generated Method Stubsetprogressbarindeterminatevisibility (False);}}); increasebtn = (Button) Findviewbyid (R.id.increasebutton);d ecreasebtn = (button) Findviewbyid (R.id.decreasebutton); MyProgressBar = (ProgressBar) Findviewbyid (R.id.progressbar01); Increasebtn.setonclicklistener (New Onclicklistener ( {@Overridepublic void OnClick (View arg0) {//TODO auto-generated method Stubmyprogressbar.incrementprogressby (1);}}); Decreasebtn.setonclicklistener (New Onclicklistener () {@Overridepublic void OnClick (View arg0) {//TODO auto-generated Method Stubmyprogressbar.incrementprogressby (-1);}});} @Overrideprotected Dialog oncreatedialog (int id) {//TODO auto-generated method Stubprogressdialog DiaLog = new ProgressDialog (this);d ialog.settitle ("Test dialog box");d Ialog.setindeterminate (True);d ialog.setmessage (" The program is loading please wait! ");d ialog.setcancelable (True); return dialog;} @Overridepublic boolean Oncreateoptionsmenu (Menu menu) {//Inflate the menu; This adds items to the action bar if it is PR Esent.getmenuinflater (). Inflate (R.menu.test__progress_bar_, menu); return true;}}


3. layout file Test_progressbar.xml

<linearlayout xmlns:android= "http://schemas.android.com/apk/res/android" android:layout_width= "Match_parent" android:layout_height= "match_parent" android:gravity= "center" android:orientation= "vertical" > <linearlayou T android:id= "@+id/linearlayout01" android:layout_width= "wrap_content" android:layout_height= "Wrap_co Ntent "android:orientation=" vertical "> <button android:id=" @+id/button01 "Andro Id:layout_width= "Wrap_content" android:layout_height= "wrap_content" android:background= "@android: Col Or/holo_blue_dark "android:text=" dialog box progress bar/> </LinearLayout> <textview android:layout_w Idth= "Fill_parent" android:layout_height= "wrap_content" android:gravity= "center" android:text= "------ ----------------------"/> <linearlayout android:id=" @+id/linearlayout02 "android:layout_width=" Wra P_content "Android:layout_height= "wrap_content" android:orientation= "horizontal" > <button android:id= "@+id/xian Shibutton "android:layout_width=" wrap_content "android:layout_height=" Wrap_content "Andro Id:text= "Show"/> <button android:id= "@+id/yincangbutton" android:layout_width= "Wrap_cont Ent "android:layout_height=" wrap_content "android:text=" hidden "/> </LinearLayout> <te Xtview android:layout_width= "fill_parent" android:layout_height= "wrap_content" android:gravity= "Cente        R "android:text="----------------------------"/> <linearlayout android:id=" @+id/linearlayout03 "  Android:layout_width= "Wrap_content" android:layout_height= "wrap_content" android:orientation= "vertical" > <progressbar android:id= "@+id/progressbar01" style= "? Android:attr/progressbarstyleho Rizontal "andRoid:layout_width= "200dip" android:layout_height= "Wrap_content" android:max= "Android" :p rogress= "/> <button android:id=" @+id/increasebutton "android:layout_width=" Wrap_c Ontent "android:layout_height=" Wrap_content "android:text=" Add "/> <button an" Droid:id= "@+id/decreasebutton" android:layout_width= "wrap_content" android:layout_height= "Wrap_conte NT "android:text=" reduction "/> </LinearLayout></LinearLayout>

4. Results presentation


There is too little descriptive text in the "note" program that needs to be improved later.

Requestwindowfeature (window.feature_indeterminate_progress) This sentence must be before Setcontentview

Android app Development (eight)----------------progress bar for common components (cont.)

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.