简体   繁体   中英

Using seekbars to change RGB values android studio

I was wondering how to change my code to make it work properly:

Red.setOnSeekBarChangeListener(new SeekBar.OnSeekBarChangeListener() {
        @Override
        public void onProgressChanged(SeekBar seekBar, int progress, boolean fromUser) {
            seekr = Red.getProgress();
            seekg = Green.getProgress();
            seekb = Blue.getProgress();
            button1.setBackgroundColor(
                    0xff000000
                            +seekr*0x10000
                            +seekg*0x100
                            +seekb
            );
            button2.setBackgroundColor(
                    0xff000000
                            +seekr*0x10000
                            +seekg*0x100
                            +seekb
            );
        }

        @Override
        public void onStartTrackingTouch(SeekBar seekBar) {

        }

        @Override
        public void onStopTrackingTouch(SeekBar seekBar) {

        }
    });

this is the method that i'm using to change the value of the Red parameter, and i'm controlling also the other 2 colors in the same way. The problem is that when all the seekbars are set on 0 the background color of the buttons is black, and if they are all set at the maximum value the background color is grey; so i can't have the white color. Why is this code not working properly?

Not sure if you are wanting white or not but could try using:

button1.SetBackgroundColor(Color.argb(255, seekr, seekg, seekb));
button2.SetBackgroundColor(Color.argb(255, seekr, seekg, seekb));

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM