ProgressBar--进度条
生活随笔
收集整理的這篇文章主要介紹了
ProgressBar--进度条
小編覺得挺不錯(cuò)的,現(xiàn)在分享給大家,幫大家做個(gè)參考.
2019獨(dú)角獸企業(yè)重金招聘Python工程師標(biāo)準(zhǔn)>>>
/*max -- 最大進(jìn)度progress -- 第一進(jìn)度secondaryProgress -- 第二進(jìn)度style -- 樣式,大中小水平*/<ProgressBarandroid:max="100" android:progress="50"android:secondaryProgress="80"style="?android:attr/progressBarStyleHorizontal"android:layout_width="match_parent"android:layout_height="wrap_content"android:id="@+id/progressBar"android:layout_gravity="center_horizontal" />add_btn = (Button)findViewById(R.id.add_button);reducer_btn = (Button)findViewById(R.id.reduce_button);reset_btn = (Button)findViewById(R.id.reset_button);protext = (TextView)findViewById(R.id.protext);progressBar = (ProgressBar)findViewById(R.id.progressBar);show_btn = (Button)findViewById(R.id.dialog_button);show_btn.setOnClickListener(this);add_btn.setOnClickListener(this);reducer_btn.setOnClickListener(this);reset_btn.setOnClickListener(this);myProtext();private void myProtext(){int first = progressBar.getProgress();int second = progressBar.getSecondaryProgress();int max = progressBar.getMax();protext.setText((int)(first/(float)max*100)+"%"+"=="+(int)(second/(float)max*100)+"%");}@Overridepublic void onClick(View v) {switch (v.getId()){case R.id.add_button:{//增加progressBar.incrementProgressBy(10);progressBar.incrementSecondaryProgressBy(10);break;}case R.id.reduce_button:{//減少progressBar.incrementProgressBy(-10);progressBar.incrementSecondaryProgressBy(-10);break;}case R.id.reset_button:{//充值progressBar.setProgress(50);progressBar.setSecondaryProgress(80);break;}case R.id.dialog_button:{//彈出進(jìn)度彈出框//初始化progressDiaog = new ProgressDialog(FourActivity.this);//顯示風(fēng)格progressDiaog.setProgressStyle(ProgressDialog.STYLE_HORIZONTAL);//標(biāo)題progressDiaog.setTitle("測(cè)試");//對(duì)話框內(nèi)的文字信息progressDiaog.setMessage("歡迎下載");//圖標(biāo)progressDiaog.setIcon(R.drawable.icon);//最大進(jìn)度progressDiaog.setMax(100);//開始進(jìn)度progressDiaog.incrementProgressBy(50);//明確顯示進(jìn)度精度progressDiaog.setIndeterminate(false);//設(shè)定按鈕progressDiaog.setButton(DialogInterface.BUTTON_POSITIVE,"確定", new DialogInterface.OnClickListener(){@Overridepublic void onClick(DialogInterface dialog, int which) {Toast.makeText(FourActivity.this,"下載結(jié)束",Toast.LENGTH_SHORT).show();}});//是否可以通過返回按鈕退出對(duì)話框progressDiaog.setCancelable(true);//顯示progressDiaog.show();break;}}myProtext();}自定義樣式
/*max -- 最大進(jìn)度progress -- 第一進(jìn)度secondaryProgress -- 第二進(jìn)度style -- 樣式,大中小水平默認(rèn)樣式 -- style="?android:attr/progressBarStyleHorizontal"自定義樣式1.先將style修改為Widget.ProgressBar.Horizontal2.覆蓋其progressDrawable屬性,路徑為自定義xml*/<ProgressBarandroid:max="100"android:progress="50"android:secondaryProgress="80"style="@android:style/Widget.ProgressBar.Horizontal"android:progressDrawable="@drawable/progress_bar"android:layout_width="match_parent"android:layout_height="wrap_content"android:id="@+id/progressBar"android:layout_gravity="center_horizontal" />progress_bar.xml<?xml version="1.0" encoding="utf-8"?> <layer-list xmlns:android="http://schemas.android.com/apk/res/android" ><item android:id="@android:id/background"><shape><corners android:radius="5dip" /><solid android:color="#88000000"/></shape></item><item android:id="@android:id/secondaryProgress"><clip><shape><corners android:radius="5dip" /><gradientandroid:angle="270"android:centerColor="#C6B7FF"android:centerY="0.75"android:endColor="#C3B2FF"android:startColor="#B9A4FF" /></shape></clip></item><item android:id="@android:id/progress"><clip><shape><corners android:radius="5dip" /><gradientandroid:angle="270"android:centerColor="#74EBFF"android:centerY="0.75"android:endColor="#8EEFFF"android:startColor="#57E8FF" /></shape></clip></item></layer-list>?
轉(zhuǎn)載于:https://my.oschina.net/u/2346786/blog/807848
總結(jié)
以上是生活随笔為你收集整理的ProgressBar--进度条的全部?jī)?nèi)容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: Linux Process VS Thr
- 下一篇: 《Raspberry Pi用户指南》——