android progressbar 加载数据,ProgressBar的使用实例

以下内容有三方式设置进度条

设置一个简单的进度条

布局

android:id="@+id/progressBar"

style="?android:attr/progressBarStyleHorizontal"

android:layout_width="match_parent"

android:max="100"

android:progressDrawable="@drawable/pg"

android:progress="50"

android:secondaryProgress="80"

android:layout_height="20dp" />

protected void onCreate(@Nullable Bundle savedInstanceState) {

super.onCreate(savedInstanceState);

//启动窗口特征(带进度条和不带进度条)

requestWindowFeature(Window.FEATURE_PROGRESS);

//不带

requestWindowFeature(Window.FEATURE_INDETERMINATE_PROGRESS);

setContentView(R.layout.activity_process);

//显示俩种进度条

setProgressBarVisibility(true);

setProgressBarIndeterminate(true);

setProgress(600);

效果图

fe44b3f1f062

image.png

设置一个进度条,类似于歌曲播放一样,显示不同颜色的进度,来设置三个按钮对其进行讲解

android:id="@+id/progressBar"

style="?android:attr/progressBarStyleHorizontal"

android:layout_width="match_parent"

android:max="100"

android:progress="50"

android:secondaryProgress="80"

android:layout_height="20dp" />

android:layout_marginTop="20dp"

android:layout_width="wrap_content"

android:layout_height="wrap_content"

android:text="@string/add"

android:id="@+id/add"/>

android:layout_width="wrap_content"

android:layout_height="wrap_content"

android:text="@string/delcline"

android:id="@+id/decline" />

android:layout_width="wrap_content"

android:layout_height="wrap_content"

android:text="@string/reset"

android:id="@+id/reset"/>

android:id="@+id/text"

android:layout_width="wrap_content"

android:layout_height="wrap_content" />

btn_add=(Button) findViewById(R.id.add);

btn_decline=(Button)findViewById(R.id.decline);

btn_reset=(Button) findViewById(R.id.reset);

dialog=(Button) findViewById(R.id.btn1);

progressBar=(ProgressBar)findViewById(R.id.progressBar);

textView=(TextView)findViewById(R.id.text);

int first= progressBar.getProgress();

int second=progressBar.getSecondaryProgress();

int max=progressBar.getMax();

textView.setText("第一进度百分比:"+(int)(first/(float)max*100)+"%"+"第二进度百分比:"+(int)(second/(float)max*100)+"%");

btn_add.setOnClickListener(this);

btn_decline.setOnClickListener(this);

btn_reset.setOnClickListener(this);

}

@Override

public void onClick(View v) {

switch (v.getId()){

case R.id.add:{

progressBar.incrementProgressBy(10);

progressBar.incrementSecondaryProgressBy(10);

break;

}

case R.id.decline:{

progressBar.incrementProgressBy(-10);

progressBar.incrementSecondaryProgressBy(-10);

break;

} case R.id.reset:{

progressBar.setProgress(50);

progressBar.setSecondaryProgress(80);

break;

}

}

}

textView.setText("第一进度百分比:"+(int)(progressBar.getProgress()/(float)progressBar.getMax()*100)+"%"+"第二进度百分比:"+(int)(progressBar.getSecondaryProgress()/(float)progressBar.getMax()*100)+"%");

}

效果图

fe44b3f1f062

zaidierzh

设置一个在对话框里显示的进度条(在第二种设置的基础上添加一个按钮)

// 带有弹框的进条

}case R.id.btn1:{

//基础页面显示风格

progressDialog=new ProgressDialog(ProgressBarActivity.this);

progressDialog.setProgressStyle(ProgressDialog.STYLE_HORIZONTAL);

progressDialog.setTitle("晨曦诗雨");

progressDialog.setMessage("欢迎来看晨曦分享小知识");

progressDialog.setIcon(R.drawable.ic_my);

//设置进度条的属性

progressDialog.setMax(100);

progressDialog.incrementProgressBy(50);

//明确显示进度

progressDialog.setIndeterminate(false);

//设置确定按钮

progressDialog.setButton(DialogInterface.BUTTON_POSITIVE,"确定", new DialogInterface.OnClickListener() {

@Override

public void onClick(DialogInterface dialog, int which) {

Toast.makeText(ProgressBarActivity.this,"欢迎支持我的分享",Toast.LENGTH_SHORT).show();

}

});

//是否通过返回按钮退出对话框

progressDialog.setCancelable(true);

progressDialog.show();

break;

}

效果图

fe44b3f1f062

image.png

设置自定义形式的进度条,改变其颜色,样式(自定设定一个样式的文件,在页面中引入)

android:angle="270"

android:centerColor="#E3E3E3"

android:endColor="#E6E6E6"

android:startColor="#C8C8C8" />

android:centerColor="#f1cd06"

android:endColor="#fff701"

android:startColor="#dace27" />

android:centerColor="#4AEA2F"

android:endColor="#31CE15"

android:startColor="#5FEC46" />

引入此样式的设置属性

android:progressDrawable="@drawable/pg"

ProgressBar是一个进度条,展示给用户某个耗时操作的完成程度

fe44b3f1f062

image.png

fe44b3f1f062

image.png

可以再标题上来设置进度条(切换一个页面加载数据时就会使用到这个功能)

fe44b3f1f062

image.png

fe44b3f1f062

image.png

注意:不显示精确度是false,反之为true

fe44b3f1f062

image.png

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值