How to change seek bar progress colour according to its progress?

你离开我真会死。 提交于 2019-12-10 15:26:13

问题


I want to create a custom seekbar, whose progress bar's colour change between red and blue as the user changes the progress of the bar.

I have tried it but its only changing the background colour not the progress bar color.

seekBar.setOnSeekBarChangeListener(new OnSeekBarChangeListener() {

            public void onStopTrackingTouch(SeekBar seekBar) {
                // TODO Auto-generated method stub

            }

            public void onStartTrackingTouch(SeekBar seekBar) {
                // TODO Auto-generated method stub

            }

            public void onProgressChanged(SeekBar seekBar, int progress,
                    boolean fromUser) {


                seekBar.setBackgroundColor(Color.RED + progress);

            }
        });

回答1:


use custom seek bar for that requirement see following link's

  1. http://www.mokasocial.com/2011/02/create-a-custom-styled-ui-slider-seekbar-in-android/

  2. Seek bar, change path color from yellow to white




回答2:


There are a lot of way to do this, I'll tell the simple way. You can set the color of progressBackground like this:

seekBar.getProgressDrawable().setColorFilter("<Color you wish>", PorterDuff.Mode.MULTIPLY);

If your api level 21, you can use getProgressBackgroundTintList or getProgressBackgroundTintMode().



来源:https://stackoverflow.com/questions/8615681/how-to-change-seek-bar-progress-colour-according-to-its-progress

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!