1

I created a simply project which uses SeekBars connected to sounds and connected to the colors of a button.

I haven't problems with the sound, but with the RGB color scale. I wrote the code but when I installed the apk on my phone, I found an error. When I move the cursor till the end, the color scale isn't complete, like this:

enter image description here

If you see, the scale isn't at the end of its color range. The problem persists also with the other two RGB SeekBars.

There's the code, what did I do wrong?

    final SeekBar r=(SeekBar)findViewById(R.id.seekBar3);
    final SeekBar g=(SeekBar)findViewById(R.id.seekBar4);
    final SeekBar b=(SeekBar)findViewById(R.id.seekBar5);
    r.setOnSeekBarChangeListener(new SeekBar.OnSeekBarChangeListener() {
        @Override
        public void onProgressChanged(SeekBar seekBar, int progress, boolean fromUser) {
            seekr = r.getProgress();
            seekg = g.getProgress();
            seekb = b.getProgress();

            button1.setBackgroundColor(
                    0xff000000
                            + seekr * 0x10000
                            + seekg * 0x100
                            + seekb
            );

            button2.setBackgroundColor(
                    0xff000000
                            + seekr * 0x10000
                            + seekg * 0x100
                            + seekb
            );


        }

        @Override
        public void onStartTrackingTouch(SeekBar seekBar) {

            //mplayer.start();
        }

        @Override
        public void onStopTrackingTouch(SeekBar seekBar) {
            //mplayer.stop();

        }
    });

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


        }

        @Override
        public void onStartTrackingTouch(SeekBar seekBar) {

            //mplayer.start();
        }

        @Override
        public void onStopTrackingTouch(SeekBar seekBar) {
            //mplayer.stop();

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


        }

        @Override
        public void onStartTrackingTouch(SeekBar seekBar) {

            //mplayer.start();
        }

        @Override
        public void onStopTrackingTouch(SeekBar seekBar) {
            //mplayer.stop();

        }
    });

}

XML:

   <SeekBar
       android:id="@+id/seekBar3"
       android:layout_width="305dp"
       android:layout_height="31dp"
       tools:layout_editor_absoluteX="59dp"
       tools:layout_editor_absoluteY="365dp"
       android:layout_marginTop="25dp"
       android:layout_below="@+id/button2"
       android:layout_alignStart="@+id/button" />

   <SeekBar
       android:id="@+id/seekBar4"
       android:layout_width="309dp"
       android:layout_height="27dp"
       tools:layout_editor_absoluteX="59dp"
       tools:layout_editor_absoluteY="459dp"
       android:layout_marginTop="30dp"
       android:layout_below="@+id/seekBar3"
       android:layout_alignStart="@+id/button" />

   <SeekBar
       android:id="@+id/seekBar5"
       android:layout_width="wrap_content"
       android:layout_height="wrap_content"
       android:layout_alignStart="@+id/seekBar4"
       android:layout_below="@+id/seekBar4"
       android:layout_marginTop="19dp"
       android:layout_alignEnd="@+id/seekBar4" />
Oğuzhan Döngül
  • 7,856
  • 4
  • 38
  • 52
P.Halley
  • 54
  • 7

1 Answers1

0

You should define the maximum value for your seekbar to be 255 using android:max="255" in your xml file.

As written in the android documentation:

By default, the progress bar is full when it reaches 100. If necessary, you can adjust the maximum value (the value for a full bar) using the android:max attribute.

regev avraham
  • 1,102
  • 1
  • 9
  • 24