style="@android:style/Widget.Holo.Light.ProgressBar" style="@android:style/Widget.DeviceDefault.Light.ProgressBar.Large" ...
style="@android:style/Widget.ProgressBar.Horizontal" style="@android:style/Widget.DeviceDefault.Light.ProgressBar.Horizontal" ...
requestWindowFeature(Window.FEATURE_INDETERMINATE_PROGRESS); setProgressBarIndeterminateVisibility(true);
requestWindowFeature(Window.FEATURE_PROGRESS); setProgressBarVisibility(true);
<!--最大显示进度--> android:max <!--第一显示进度--> android:progress <!--第二显示进度--> android:secondaryProgress <!--置是否精确显示;true为不精确,false为精确--> android:indeterminate <!--加载自定义样式--> android:progressDrawable
<?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="10dip" />
<!--填充色-->
<solid android:color="#dddddd" />
</shape>
</item>
<!--第二进度样式-->
<item android:id="@android:id/secondaryProgress">
<clip>
<shape>
<corners android:radius="10dip" />
<solid android:color="#78bb78" />
</shape>
</clip>
</item>
<!--第一进度样式-->
<item android:id="@android:id/progress">
<clip>
<shape>
<corners android:radius="10dip" />
<solid android:color="#55bb55" />
</shape>
</clip>
</item>
</layer-list>
//设置第一进度 setProgress(int) //设置第二进度 setSecondaryProgress(int) //获取第一进度 getProgress() //获取第二进度 getSecondaryProgress() //增加或减少第一进度 incrementProgressBy(int) //增加或减少第二进度 incrementSecondaryProgressBy(int) //获取进度最大值 getMax()
public class ProgessBarActivity extends Activity implements View.OnClickListener{
private ProgressBar progressBar;
private TextView text;
private Button addFirst;
private Button addSecond;
private Button subFirst;
private Button subSecond;
private Button reset;
private int first;
private int second;
private int max;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_progess_bar);
init();
}
private void init() {
progressBar = (ProgressBar) findViewById(R.id.progress_bar);
text = (TextView) findViewById(R.id.text);
addFirst = (Button) findViewById(R.id.add_first);
subFirst = (Button) findViewById(R.id.sub_first);
addSecond = (Button) findViewById(R.id.add_second);
subSecond = (Button) findViewById(R.id.sub_second);
reset = (Button) findViewById(R.id.reset);
//获取第一、第二、最大进度
first = progressBar.getProgress();
second = progressBar.getSecondaryProgress();
max = progressBar.getMax();
addFirst.setOnClickListener(this);
addSecond.setOnClickListener(this);
subFirst.setOnClickListener(this);
subSecond.setOnClickListener(this);
reset.setOnClickListener(this);
}
@Override
public void onClick(View v) {
switch (v.getId()) {
case R.id.add_first:
//第一进度加10
progressBar.incrementProgressBy(10);
break;
case R.id.add_second:
//第二进度加10
progressBar.incrementSecondaryProgressBy(10);
break;
case R.id.sub_first:
progressBar.incrementProgressBy(-10);
break;
case R.id.sub_second:
progressBar.incrementSecondaryProgressBy(-10);
break;
case R.id.reset:
//重置为初始数值
progressBar.setProgress(30);
progressBar.setSecondaryProgress(60);
break;
}
//更新文本内容
text.setText("第一进度为" + (int) (1.0*first/max*100) + "%,第二进度为" + (int) (1.0*second/max*100) + "%");
}
}
ProgressDialog(Context context) ProgressDialog(Context context, int theme)//theme为对话框样式
//设置进度条样式 setProgressStyle(int style) //设置对话框标题 setTitle(String title) //设置对话框本文信息 setMessage(CharSequence message) //设置对话框图标 setIcon(Drawable d) //设置按钮,whichButton为按钮类型,text为按钮名称,listener为监听器 setButton(int whichButton, CharSequence text, OnClickListener listener) //显示对话框 show()
public class ProgressDialogActivity extends Activity {
private ProgressDialog proDialog;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_progress_dialog);
findViewById(R.id.show).setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
//新建对话框
proDialog = new ProgressDialog(ProgressDialogActivity.this);
//设置进度条样式
proDialog.setProgressStyle(ProgressDialog.STYLE_HORIZONTAL);
//设置对话框标题
proDialog.setTitle("初识ProgressDialog");
//设置提示对话框文本
proDialog.setMessage("好好学习,天天向上!");
//设置对话框显示图标
proDialog.setIcon(R.drawable.ic_launcher);
//设置进度条最大进度,默认为10000
proDialog.setMax(100);
//设置初始第一进度
proDialog.incrementProgressBy(30);
//设定取消按钮
proDialog.setButton(DialogInterface.BUTTON_POSITIVE, "取消", new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
dialog.cancel();
}
});
//显示对话框
proDialog.show();
}
});
}
}
机械节能产品生产企业官网模板...
大气智能家居家具装修装饰类企业通用网站模板...
礼品公司网站模板
宽屏简约大气婚纱摄影影楼模板...
蓝白WAP手机综合医院类整站源码(独立后台)...苏ICP备2024110244号-2 苏公网安备32050702011978号 增值电信业务经营许可证编号:苏B2-20251499 | Copyright 2018 - 2025 源码网商城 (www.ymwmall.com) 版权所有