java进度条字体颜色,以编程方式设置进度条进度颜色

I am showing the progress bar while downloading files.I want to set the color(HTML color code) of the progress which comes from the server and may vary the color code time to time.

how do i meet the requirement.

KDqEW.png.

For example for the above image i want to change yellow color and set the color which comes server.

解决方案

So...I made a sample project that changes the progress color and you also can change the background progress bar color.

First create a custom progress bar xml file.

custom_progressbar.xml

android:startColor="#000001"

android:centerColor="#0b131e"

android:centerY="1.0"

android:endColor="#0d1522"

android:angle="270"

/>

android:startColor="#2A98E1"

android:centerColor="#2A98E1"

android:centerY="1.0"

android:endColor="#06101d"

android:angle="270"

/>

Activity Layout:

activity_my.xml

xmlns:tools="http://schemas.android.com/tools"

android:layout_width="match_parent"

android:layout_height="match_parent"

android:paddingLeft="@dimen/activity_horizontal_margin"

android:paddingRight="@dimen/activity_horizontal_margin"

android:paddingTop="@dimen/activity_vertical_margin"

android:paddingBottom="@dimen/activity_vertical_margin"

android:orientation="horizontal"

tools:context=".MyActivity">

android:id="@+id/myProgress"

style="?android:attr/progressBarStyleHorizontal"

android:layout_width="match_parent"

android:layout_weight="0.7"

android:layout_height="wrap_content" />

android:id="@+id/progressTextView"

android:layout_width="wrap_content"

android:layout_height="wrap_content"

android:text="None"/>

The test activity:

The important part is this:

Drawable draw=getResources().getDrawable(R.drawable.custom_progressbar);

progressBar.setProgressDrawable(draw);

MyActivity.java

private ProgressBar progressBar;

private Handler handler = new Handler();

private int progressStatus = 0;

private TextView textView;

@Override

protected void onCreate(Bundle savedInstanceState) {

super.onCreate(savedInstanceState);

super.onCreate(savedInstanceState);

setContentView(R.layout.activity_my);

init();

initProgresBar();

}

public void init(){

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

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

Drawable draw=getResources().getDrawable(R.drawable.custom_progressbar);

// set the drawable as progress drawable

progressBar.setProgressDrawable(draw);

}

public void initProgresBar(){

new Thread(new Runnable() {

public void run() {

while (progressStatus < 100) {

progressStatus += 1;

// Update the progress bar and display the

//current value in the text view

handler.post(new Runnable() {

public void run() {

progressBar.setProgress(progressStatus);

textView.setText(progressStatus+"/"+progressBar.getMax());

}

});

try {

// Sleep for 200 milliseconds.

//Just to display the progress slowly

Thread.sleep(200);

} catch (InterruptedException e) {

e.printStackTrace();

}

}

}

}).start();

}

And the output will be this:

AjNEV.png

Hope this is what you where looking for. Cheers

For more info you will find this usefull: stack progress bar post

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值