?
多式樣ProgressBar
普通圓形ProgressBar
該類型進(jìn)度條也就是一個(gè)表示運(yùn)轉(zhuǎn)的過程,例如發(fā)送短信,連接網(wǎng)絡(luò)等等,表示一個(gè)過程正在執(zhí)行中。
一般只要在XML布局中定義就可以了。
Java代碼 ?
<progressBar?android:id="@+id/widget43"????????android:layout_width="wrap_content"?????????android:layout_height="wrap_content"????????????android:layout_gravity="center_vertical">??</ProgressBar>?? <progressBar android:id="@+id/widget43"android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_gravity="center_vertical">
</ProgressBar>
此時(shí),沒有設(shè)置它的風(fēng)格,那么它就是圓形的,一直會(huì)旋轉(zhuǎn)的進(jìn)度條。
各大小樣式圓形ProgressBar
超大號(hào)圓形ProgressBar
此時(shí),給設(shè)置一個(gè)style風(fēng)格屬性后,該P(yáng)rogressBar就有了一個(gè)風(fēng)格,
這里大號(hào)ProgressBar的風(fēng)格是:
Java代碼 ?
style="?android:attr/progressBarStyleLarge"?? style="?android:attr/progressBarStyleLarge" 完整
XML定義是:
Java代碼 ?
?<progressBar?android:id="@+id/widget196"????????android:layout_width="wrap_content"?????????android:layout_height="wrap_content"????????style="?android:attr/progressBarStyleLarge">??</ProgressBar>?? <progressBar android:id="@+id/widget196"android:layout_width="wrap_content" android:layout_height="wrap_content"style="?android:attr/progressBarStyleLarge">
</ProgressBar>
小號(hào)圓形ProgressBar
小號(hào)ProgressBar對(duì)應(yīng)的風(fēng)格是:
Java代碼 ?
style="?android:attr/progressBarStyleSmall"?? style="?android:attr/progressBarStyleSmall"
完整XML定義是:
Java代碼 ?
<progressBar?android:id="@+id/widget108"????????android:layout_width="wrap_content"?????????android:layout_height="wrap_content"????????style="?android:attr/progressBarStyleSmall">??</ProgressBar>?? <progressBar android:id="@+id/widget108"android:layout_width="wrap_content" android:layout_height="wrap_content"style="?android:attr/progressBarStyleSmall">
</ProgressBar>
標(biāo)題型圓形ProgressBar
標(biāo)題型ProgressBar對(duì)應(yīng)的風(fēng)格是:
Java代碼 ?
style="?android:attr/progressBarStyleSmallTitle"?? style="?android:attr/progressBarStyleSmallTitle" 完整XML定義是:
Java代碼 ?
<progressBar?android:id="@+id/widget110"??????android:layout_width="wrap_content"???????android:layout_height="wrap_content"??????style="?android:attr/progressBarStyleSmallTitle">??</ProgressBar>?? <progressBar android:id="@+id/widget110"android:layout_width="wrap_content" android:layout_height="wrap_content"style="?android:attr/progressBarStyleSmallTitle">
</ProgressBar>
代碼中實(shí)現(xiàn):
??? Java代碼 ?
protected?void?onCreate(Bundle?savedInstanceState)?{??????????????????????super.onCreate(savedInstanceState);????????????requestWindowFeature(Window.FEATURE_INDETERMINATE_PROGRESS);??????????????????????setContentView(R.layout.second);????????????setProgressBarIndeterminateVisibility(true);??????????????????}?? protected void onCreate(Bundle savedInstanceState) {// TODO Auto-generated method stubsuper.onCreate(savedInstanceState);requestWindowFeature(Window.FEATURE_INDETERMINATE_PROGRESS);//請(qǐng)求窗口特色風(fēng)格,這里設(shè)置成不明確的進(jìn)度風(fēng)格setContentView(R.layout.second);setProgressBarIndeterminateVisibility(true);//設(shè)置標(biāo)題欄中的不明確的進(jìn)度條是否可以顯示}
長形進(jìn)度條
布局中的長形進(jìn)度條
①首先在XML進(jìn)行布局
Java代碼 ?
<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"????/>??? <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" />
講解:
Java代碼 ?
style="?android:attr/progressBarStyleHorizontal"??? style="?android:attr/progressBarStyleHorizontal" ?
設(shè)置風(fēng)格為長形
Java代碼 ?
android:max="100"??? android:max="100" ?
最大進(jìn)度值為100
Java代碼 ?
android:progress="50"???? android:progress="50"
初始化的進(jìn)度值
Java代碼 ?
android:secondaryProgress="70"??? android:secondaryProgress="70"
初始化的底層第二個(gè)進(jìn)度值
Java代碼 ?
android:layout_gravity="center_vertical"????? android:layout_gravity="center_vertical"
垂直居中
②代碼中運(yùn)用
Java代碼 ?
private?ProgressBar?myProgressBar;??????myProgressBar?=?(ProgressBar)?findViewById(R.id.progressbar_updown);??????myProgressBar.incrementProgressBy(5);??????myProgressBar.incrementProgressBy(-5);??????myProgressBar.incrementSecondaryProgressBy(5);??????myProgressBar.incrementSecondaryProgressBy(-5);??????? private ProgressBar myProgressBar;//定義ProgressBarmyProgressBar = (ProgressBar) findViewById(R.id.progressbar_updown);//ProgressBar通過ID來從XML中獲取myProgressBar.incrementProgressBy(5);//ProgressBar進(jìn)度值增加5myProgressBar.incrementProgressBy(-5);//ProgressBar進(jìn)度值減少5myProgressBar.incrementSecondaryProgressBy(5);//ProgressBar背后的第二個(gè)進(jìn)度條 進(jìn)度值增加5myProgressBar.incrementSecondaryProgressBy(-5);//ProgressBar背后的第二個(gè)進(jìn)度條 進(jìn)度值減少5
頁面標(biāo)題中的長形進(jìn)度條
代碼實(shí)現(xiàn):
①先設(shè)置一下窗口風(fēng)格特性
Java代碼 ?
requestWindowFeature(Window.FEATURE_PROGRESS);?? requestWindowFeature(Window.FEATURE_PROGRESS);
//請(qǐng)求一個(gè)窗口進(jìn)度條特性風(fēng)格
Java代碼 ?
setContentView(R.layout.main);????setProgressBarVisibility(true);?? setContentView(R.layout.main);setProgressBarVisibility(true);
//設(shè)置進(jìn)度條可視
②然后設(shè)置進(jìn)度值
Java代碼 ?
setProgress(myProgressBar.getProgress()?*?100);?? setProgress(myProgressBar.getProgress() * 100);
//設(shè)置標(biāo)題欄中前景的一個(gè)進(jìn)度條進(jìn)度值
Java代碼 ?
setSecondaryProgress(myProgressBar.getSecondaryProgress()?*?100);?? setSecondaryProgress(myProgressBar.getSecondaryProgress() * 100);
//設(shè)置標(biāo)題欄中后面的一個(gè)進(jìn)度條進(jìn)度值
//ProgressBar.getSecondaryProgress() 是用來獲取其他進(jìn)度條的進(jìn)度值
ProgressDialog
ProgressDialog中的圓形進(jìn)度條
?????
ProgressDialog一般用來表示一個(gè)系統(tǒng)任務(wù)或是開啟任務(wù)時(shí)候的進(jìn)度,有一種稍等的意思。
代碼實(shí)現(xiàn):
Java代碼 ?
ProgressDialog?mypDialog=new?ProgressDialog(this);????????????????????????????mypDialog.setProgressStyle(ProgressDialog.STYLE_SPINNER);????????????????????????????mypDialog.setTitle("Google");????????????????????????????mypDialog.setMessage(getResources().getString(R.string.second));????????????????????????????mypDialog.setIcon(R.drawable.android);????????????????????????????mypDialog.setButton("Google",this);????????????????????????????mypDialog.setIndeterminate(false);????????????????????????????mypDialog.setCancelable(true);????????????????????????????mypDialog.show();??????????????? ProgressDialog mypDialog=new ProgressDialog(this);//實(shí)例化mypDialog.setProgressStyle(ProgressDialog.STYLE_SPINNER);//設(shè)置進(jìn)度條風(fēng)格,風(fēng)格為圓形,旋轉(zhuǎn)的mypDialog.setTitle("Google");//設(shè)置ProgressDialog 標(biāo)題mypDialog.setMessage(getResources().getString(R.string.second));//設(shè)置ProgressDialog 提示信息mypDialog.setIcon(R.drawable.android);//設(shè)置ProgressDialog 標(biāo)題圖標(biāo)mypDialog.setButton("Google",this);//設(shè)置ProgressDialog 的一個(gè)ButtonmypDialog.setIndeterminate(false);//設(shè)置ProgressDialog 的進(jìn)度條是否不明確mypDialog.setCancelable(true);//設(shè)置ProgressDialog 是否可以按退回按鍵取消mypDialog.show();//讓ProgressDialog顯示
ProgressDialog中的長形進(jìn)度條
?????
代碼實(shí)現(xiàn):
Java代碼 ?
ProgressDialog?mypDialog=new?ProgressDialog(this);??????????????????mypDialog.setProgressStyle(ProgressDialog.STYLE_HORIZONTAL);??????????????????????????????mypDialog.setTitle("地獄怒獸");??????????????????????????????mypDialog.setMessage(getResources().getString(R.string.second));??????????????????????????????mypDialog.setIcon(R.drawable.android);??????????????????????????????mypDialog.setProgress(59);??????????????????????????????mypDialog.setButton("地獄曙光",this);??????????????????????????????mypDialog.setIndeterminate(false);??????????????????????????????mypDialog.setCancelable(true);??????????????????????????????mypDialog.show();??????????????????????AlertDialog.Builder????AlertDialog中的圓形ProgressBar ?
轉(zhuǎn)載于:https://www.cnblogs.com/gtgl/p/3906620.html
總結(jié)
以上是生活随笔為你收集整理的ProgressBar 各种样式的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。
如果覺得生活随笔網(wǎng)站內(nèi)容還不錯(cuò),歡迎將生活随笔推薦給好友。