Progress進(jìn)度條的實(shí)現(xiàn)
package?com.example.administrator.progressbar; import?android.app.ActionBar; import?android.app.Activity; import?android.app.ProgressDialog; import?android.content.DialogInterface; import?android.os.Bundle; import?android.util.Property; import?android.view.Menu; import?android.view.MenuItem; import?android.view.View; import?android.view.Window; import?android.widget.Button; import?android.widget.ProgressBar; import?android.widget.Toast; public?class?MainActivity?extends?Activity?implements?Button.OnClickListener{ ????private?ProgressBar?progressBar; ????private?Button?btn_add; ????private?Button?btn_sub; ????private?Button?btn_reset; ????private?Button?btn_dialog; ????@Override ????protected?void?onCreate(Bundle?savedInstanceState)?{ ????????super.onCreate(savedInstanceState); ????????/** ?????????*?actionBar?進(jìn)度條 ?????????*/ ????????//?1、設(shè)置窗口特征 ????????requestWindowFeature(Window.FEATURE_PROGRESS);?//進(jìn)度條 ????????requestWindowFeature(Window.FEATURE_INDETERMINATE_PROGRESS);?//loading ????????setContentView(R.layout.activity_main); ????????//?2、顯示進(jìn)度條 ????????setProgressBarVisibility(true); ????????//?2、顯示loading ????????setProgressBarIndeterminateVisibility(true); ????????setProgress(Window.PROGRESS_END?/?2);?//進(jìn)度條長(zhǎng)度為50%?最大為?10000 ????????/** ?????????*?進(jìn)度條組件 ?????????*/ ????????//?1、 ????????progressBar?=?(ProgressBar)findViewById(R.id.progressBar4); ????????btn_add?=?(Button)findViewById(R.id.btn_add); ????????btn_sub?=?(Button)findViewById(R.id.btn_sub); ????????btn_reset?=?(Button)findViewById(R.id.btn_reset); ????????btn_add.setOnClickListener(this); ????????btn_sub.setOnClickListener(this); ????????btn_reset.setOnClickListener(this); ????????/** ?????????*?進(jìn)度條對(duì)話框 ?????????*/ ????????btn_dialog?=?(Button)findViewById(R.id.btn_dialog); ????????btn_dialog.setOnClickListener(new?View.OnClickListener()?{ ????????????@Override ????????????public?void?onClick(View?v)?{ ????????????????ProgressDialog?progressBar_dialog?=?new?ProgressDialog(MainActivity.this); ????????????????progressBar_dialog.setTitle("進(jìn)度條對(duì)話框"); ????????????????progressBar_dialog.setMessage("進(jìn)度條對(duì)話框描述"); ????????????????progressBar_dialog.setIcon(R.mipmap.ic_launcher); ????????????????progressBar_dialog.setProgressStyle(ProgressDialog.STYLE_HORIZONTAL); ????????????????//這里不使用?setProgress、setSecondaryProgress?因?yàn)橹粫?huì)改變進(jìn)度條?不會(huì)改變進(jìn)度條下面的百分比文字 ????????????????progressBar_dialog.incrementProgressBy(50); ????????????????progressBar_dialog.incrementSecondaryProgressBy(80); ????????????????progressBar_dialog.setMax(100); ????????????????progressBar_dialog.setButton(DialogInterface.BUTTON_POSITIVE,?"確定",?new?DialogInterface.OnClickListener()?{ ????????????????????@Override ????????????????????public?void?onClick(DialogInterface?dialog,?int?which)?{ ????????????????????????Toast.makeText(MainActivity.this,?"點(diǎn)擊了確定",?Toast.LENGTH_SHORT).show(); ????????????????????} ????????????????}); ????????????????//不允許通過(guò)返回鍵關(guān)閉dialog?默認(rèn)為?true ????????????????progressBar_dialog.setCancelable(false); ????????????????progressBar_dialog.show(); ????????????} ????????}); ????} ????@Override ????public?void?onClick(View?v)?{ ????????int?_progress?=?progressBar.getProgress(); ????????int?_second_progress?=?progressBar.getSecondaryProgress(); ????????switch?(v.getId()){ ????????????case?R.id.btn_add: ????????????????progressBar.incrementProgressBy(10); ????????????????progressBar.incrementSecondaryProgressBy(10); ????????????????break; ????????????case?R.id.btn_sub: ????????????????progressBar.setProgress(_progress?-?10); ????????????????progressBar.setSecondaryProgress(_second_progress?-?10); ????????????????break; ????????????case?R.id.btn_reset: ????????????????progressBar.setProgress(50); ????????????????progressBar.setSecondaryProgress(80); ????????????????break; ????????} ????} }
ActivityMain.xml
Progress_style.xml