简体   繁体   English

使用搜索栏更改RGB值android studio

[英]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. 这是我用来更改Red参数值的方法,并且我也以相同的方式控制其他2种颜色。 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; 问题在于,当所有搜索栏均设置为0时,按钮的背景色为黑色,如果所有按钮均设置为最大值,则背景色为灰色; 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));

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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