gpt4 book ai didi

android - 在运行时以编程方式在 android 中更改自定义进度轮中的颜色

转载 作者:塔克拉玛干 更新时间:2023-11-02 22:21:36 24 4
gpt4 key购买 nike

我正在做自定义圆形进度轮。这是我需要的,一旦进度轮完成百分百的进度。然后,当我再次单击时,我需要在运行时更改进度颜色...

我从这个链接下载了代码.. https://github.com/Todd-Davies/ProgressWheel

注意:我点击一个按钮,进度开始进行。那个进度条圈已经有一种颜色了。进度完成 100% 后,我想让它重新开始,那个时候,我需要在运行时将颜色更改为红色...

我也试过这个链接..这个链接用于默认进度条。但是,我正在使用自定义进度条。这就是为什么,我不能像这样使用这种方法...... http://myandroidsolutions.blogspot.in/2012/11/android-change-indeterminate-progress.html http://www.tiemenschut.com/how-to-customize-android-progress-bars/

谁能帮我完成这个任务..提前致谢....

我的代码: onCreate 方法:

increment.setOnClickListener(new OnClickListener() {
@SuppressLint("WrongCall")
public void onClick(View v) {
Log.v("test", "-----increment button clicked--------");
if(!running) {
progress1 = (int) 370 ;
Thread s = new Thread(r);
s.start();
}
}
});

final Runnable r = new Runnable() {
@SuppressLint("WrongCall")
public void run() {
//Log.v("test", "----- thread called--------");
running = true;
//Log.v("test", "progress:"+progress);
//Log.v("test", "progress1:"+progress1);
progress2 = progress - progress1 ;
//progress = 360 , progress1 = uservalue
Log.v("test", "progress:"+progress);
Log.v("test", "progress1:"+progress1);
Log.v("test", "progress2 = progress - progress1:"+progress2);
//percentage = pw_two.incrementProgress();
// pw_two.setBarColor(Color.parseColor("#FF0000"));

while(progress2<360) {
percentage = pw_two.incrementProgress();
Log.v("test","percentage:"+percentage);
progress2++;
try {
Thread.sleep(15);
} catch (InterruptedException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}



// here when crossing 360 above , then color change effect needed..
//why we using this function, when put ten minutes for break,
who taking more than ten minutes,,
// then that time itself, need to change color..
i finish that time calculation....
if(progress2 > 359) {
// here.. need to call this method two times.. then only, wheel will be refreshed......
//onPause_Reset_ProgressWheelOne();
onPause_Reset_ProgressWheelOne();
//break;
}
}

running = false;
}
};

public void onPause_Reset_ProgressWheelOne() {

Log.v("test", "onPause_Reset_ProgressWheelOne--------");

progress = 360;
pw_two.setRimColor(Color.parseColor("#fe854c")); //1988c4 //fe854c
pw_two.setBarColor(Color.RED);
//pw_two.resetCount();
pw_two.refreshWheel();
// progress = 0;
// pw_two.setProgress(0);

}

ProgressWheel.java CLass :

public void refreshWheel() {

setupPaints();
}

最佳答案

ProgressWheel.java (com.todddavies.components.progressbar.ProgressWheel) 中,添加一个方法:

public void refreshTheWheel() {

setupPaints();

}

I click on a button, the progress starts progressing. that progress bar circle already one color. After the progress complete 100%, I want it to start again, that time , i need to change the color to be red runtimely

当你需要改变颜色时:

// Progress is 100%
if (progress == 360) {

// Change the color
mProgressWheel.setBarColor(Color.RED);

// Refresh
mProgressWheel.refreshTheWheel();

// Reset progress
progress = 0;
mProgressWheel.setProgress(0);

// You can also use:
// mProgressWheel.resetCount();
}

注意:请确保允许编辑/添加到此库。

编辑:

查看以下更改是否为您提供了所需的输出:

声明全局变量:

// `progress` isn't needed
// int progress = 360;
int progress1 = 0;
int progress2 = 0;

....
....

increment.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {

Log.v("test", "-----increment button clicked--------");

if(!running) {

// I am not sure what you are using `progress1` for
// progress1 = (int) 370 ;

progress1 = 0;
progress2 = 0;

// reset `pw_two`
pw_two.resetCount();

Thread s = new Thread(r);
s.start();
}
}
});

现在,Runnable:

final Runnable r = new Runnable() {
public void run() {
running = true;

// I could not figure out why you are using this
// Can you explain what this does?
// progress2 = progress - progress1 ;

while(progress2 < 361) {
pw_two.incrementProgress();

// Increment both `progress1` and `progress2`
progress2++;
progress1++;

try {
Thread.sleep(15);
} catch (InterruptedException e) {
e.printStackTrace();
}

// Here, reset `progress2`, but not `progress1`
if (progress2 == 360) {
pw_two.setRimColor(Color.parseColor("#fe854c")); //1988c4 //fe854c
pw_two.setBarColor(Color.RED);
pw_two.refreshWheel();
progress2 = 0;
pw_two.setProgress(0);

// Log value of `progress1`
Log.v("Progress 1", "progress1 is " + progress1);
}
}
running = false;
}
};

您不需要调用其他方法。在 progressValue = 360 处,颜色将切换。如果我以某种方式误解了您要实现的目标,您能否用一些用例进行解释?

关于android - 在运行时以编程方式在 android 中更改自定义进度轮中的颜色,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18503718/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com