<Relativelayoutxmlns:android= "Http://schemas.android.com/apk/res/android"Xmlns:tools= "Http://schemas.android.com/tools"Android:layout_width= "Match_parent"Android:layout_height= "Match_parent"> <ButtonAndroid:id= "@+id/bn1"Android:layout_width= "Wrap_content"Android:layout_height= "Wrap_content"Android:layout_alignparentleft= "true"Android:layout_alignparenttop= "true"Android:text= "Display" /> <ButtonAndroid:id= "@+id/bn2"Android:layout_width= "Wrap_content"Android:layout_height= "Wrap_content"Android:layout_alignparenttop= "true"Android:layout_centerhorizontal= "true"Android:text= "hidden" /> </Relativelayout>
PackageCom.example.titleprogressbar;Importandroid.app.Activity;ImportAndroid.os.Bundle;ImportAndroid.view.View;ImportAndroid.view.View.OnClickListener;ImportAndroid.view.Window;ImportAndroid.widget.Button; Public classMainactivityextendsActivity {@Overrideprotected voidonCreate (Bundle savedinstancestate) {Super. OnCreate (savedinstancestate); //Set the window feature to enable the progress bar showing progressrequestwindowfeature (window.feature_progress); //Set the window feature to enable a progress bar that does not show progressrequestwindowfeature (window.feature_indeterminate_progress); Setcontentview (R.layout.activity_main); Button BN1=(Button) Findviewbyid (R.ID.BN1); Button BN2=(Button) Findviewbyid (R.ID.BN2); Bn1.setonclicklistener (NewOnclicklistener () {@Override Public voidOnClick (View v) {//Show progress bar without progressSetprogressbarindeterminatevisibility (true); //Show progress bar with ProgressSetprogressbarvisibility (true); //set progress for progress barSetprogress (4500); } }); Bn2.setonclicklistener (NewOnclicklistener () {@Override Public voidOnClick (View v) {//hide the progress bar without progressSetprogressbarindeterminatevisibility (false); //Hide Progress bar with ProgressSetprogressbarvisibility (false); } }); }}
Android 21st Lesson--titlerogressbar