颜色改变自定义进度轮在运行中的Andr​​oid编程自定义、进度、颜色、oid

2023-09-06 11:16:47 作者:且放白鹿青崖间

我在做自定义圆形进度轮。在这里我需要的,一旦取得进展轮结束它百分之百的进展。然后,当我再次点击,我需要改变颜色的进展在运行时...

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

请注意:我点击一个按钮,进度开始取得进展。该进度条圈已经一个颜色。之后,我希望它重新开始,当时的进度完成100%,我需要改变颜色为红色runtimely ...

我试过这个链接也..这个链接是关于具有缺省的进度条。 但是,我使用了自定义进度bar.thats为什么,我不能用这种方法就像... 的http://myandroidsolutions.blogspot.in/2012/11/android-change-indeterminate-progress.html http://www.tiemenschut.com/how-to-customize- Android的进度条/

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

我的code:      onCreate方法:

  increment.setOnClickListener(新OnClickListener(){
@燮pressLint(WrongCall)
公共无效的onClick(视图v){
Log.v(测试,-----增加按钮点击--------);
如果(!运​​行){
progress1 =(INT)370;
螺纹s =新主题(R);
s.start();
}
}
});

最终的可运行R =新的Runnable(){
        @燮pressLint(WrongCall)
        公共无效的run(){
            //Log.v("test,-----线程调用--------);
            运行=真;
            //Log.v("test,进步+进步);
            //Log.v("test,progress1:+ progress1);
            progress2 =进展 -  progress1;
                          //进度= 360,progress1 = uservalue
            Log.v(测试,进步+进步);
            Log.v(测试,progress1:+ progress1);
            Log.v(测试,progress2 =进步 -  progress1:+ progress2);
            //百分比= pw_two.incrementProgress();
            // pw_two.setBarColor(Color.parseColor(#FF0000));

            而(progress2< 360){
            百分比= pw_two.incrementProgress();
            Log.v(测试,百分比+百分比);
                progress2 ++;
                尝试 {
                    视频下载(15);
                }赶上(InterruptedException异常E){
                    // TODO自动生成的catch块
                    e.printStackTrace();
                }



 //这里上面渡360时,则色彩变化效果需要..
 //为什么我们使用此功能,当断放了十几分钟,
    谁走十多分钟,,
 //那么时间本身,需要改变颜色..
   我完成了时间计算....
                如果(progress2> 359){
//这里..需要调用该方法两次..然后只,车轮就会被刷新......
                    // onPause_Reset_ProgressWheelOne();
                    onPause_Reset_ProgressWheelOne();
                    //打破;
                }
            }

            运行= FALSE;
        }
     };

  公共无效onPause_Reset_ProgressWheelOne(){

     Log.v(测试,onPause_Reset_ProgressWheelOne --------);

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

  }

 ProgressWheel.java类:

  公共无效refreshWheel(){

    setupPaints();
}
 

解决方案

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

 公共无效refreshTheWheel(){

    setupPaints();

}
 

  

我点击一个按钮,进度开始取得进展。该进度条圈已经一个颜色。之后,我希望它重新开始,当时的进度完成100%,我需要改变颜色为红色runtimely

当你需要改变的颜色:

  //进度为100%
如果(进度== 360){

    //改变颜色
    mProgressWheel.setBarColor(Color.RED);

    //刷新
    mProgressWheel.refreshTheWheel();

    //重置进度
    进度= 0;
    mProgressWheel.setProgress(0);

    //你也可以使用:
    // mProgressWheel.resetCount();
}
 

注:请确保编辑/添加到该库是允许的。

编辑:

看看下面的变化得到你所需要的输出:

声明全局变量:

  //`progress`不需要
// INT进度= 360;
INT progress1 = 0;
INT progress2 = 0;

....
....

increment.setOnClickListener(新OnClickListener(){
    @覆盖
    公共无效的onClick(视图v){

        Log.v(测试,-----增加按钮点击--------);

        如果(!运​​行){

            //我不知道你使用的是`progress1`为
            // progress1 =(INT)370;

            progress1 = 0;
            progress2 = 0;

            //重新设置`pw_two`
            pw_two.resetCount();

            螺纹s =新主题(R);
            s.start();
        }
    }
});
 

现在,在的Runnable

 最终可运行R =新的Runnable(){
    公共无效的run(){
        运行=真;

        //我不明白,为什么您要使用此
        //你能解释一下这是什么呢?
        // progress2 =进展 -  progress1;

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

            //增加两个`progress1`和`progress2`
            progress2 ++;
            progress1 ++;

            尝试 {
                视频下载(15);
            }赶上(InterruptedException异常E){
                e.printStackTrace();
            }

            //这里,复位'progress2`,但不是`progress1`
            如果(progress2 == 360){
                pw_two.setRimColor(Color.parseColor(#fe854c)); // 1988c4 // fe854c
                pw_two.setBarColor(Color.RED);
                pw_two.refreshWheel();
                progress2 = 0;
                pw_two.setProgress(0);

                //登录`progress1`的价值
                Log.v(进步1,progress1为+ progress1);
            }
        }
        运行= FALSE;
    }
};
 

您不需要调用另一个方法。在 progressValue = 360 ,颜色会切换。如果我有点误解你正在努力实现的东西,你能不能用一些用例解释?

I am doing for custom circular progress wheel. here what i need for, once the progress wheel finish it hundred percent progress. then , when i click again,i need to change the progressing color at runtime...

I downloaded code from this link.. https://github.com/Todd-Davies/ProgressWheel

note : 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...

I tried this link also.. this link is for having for default progress bar. but, i am using for custom progress bar.thats why, i cant used this method like... http://myandroidsolutions.blogspot.in/2012/11/android-change-indeterminate-progress.html http://www.tiemenschut.com/how-to-customize-android-progress-bars/

can anyone help me to complete this task.. Thanks Advance....

my code : onCreate Method:

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();
}

解决方案

Inside ProgressWheel.java (com.todddavies.components.progressbar.ProgressWheel), add a method:

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

When you need to change the color:

// 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();
}

Note: Please make sure that editing/adding to this library is allowed.

Edit:

See if the following changes get you the desired output:

Declare global variables:

// `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();
        }
    }
});    

Now, the 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;
    }
};

You do not need to call another method. At progressValue = 360, the color will switch. If I somehow misunderstood what you are trying to achieve, could you explain with some use-cases?