Pergunta

I am trying to figure out how to use the argb method from http://developer.android.com/reference/android/graphics/Color.html.

I've read through it multiple times and I still can't get this app to work. I'm trying to get the View widget to display the color made from moving the 4 sliders but no colors show no matter where I put the sliders. I thought that the argb method would return a value into colorValue and I would be able to use that as a color? Any suggestions would be appreciated!

My main class looks like this:

public class ColorChooserActivity extends Activity
implements OnSeekBarChangeListener {
    //variables
private SeekBar redSeekBar;
private SeekBar greenSeekBar;
private SeekBar blueSeekBar;
private SeekBar alphaSeekBar;
private View colorView;
private TextView colorTextView;

//instanced variables
private static int colorValue = 0;
private int RedValue = 0;
private int GreenValue = 0;
private int BlueValue =0;
private int AlphaValue =0;


@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_color_chooser);

    //reference to widgets
    redSeekBar = (SeekBar) findViewById(R.id.redSeekBar);
    greenSeekBar = (SeekBar) findViewById(R.id.greenSeekBar);
    blueSeekBar = (SeekBar) findViewById(R.id.blueSeekBar);
    alphaSeekBar = (SeekBar) findViewById(R.id.alphaSeekBar);
    colorView = (View) findViewById(R.id.colorView);
    colorTextView = (TextView) findViewById(R.id.colorTextView);

    //listener
    redSeekBar.setOnSeekBarChangeListener(this);
    greenSeekBar.setOnSeekBarChangeListener(this);
    blueSeekBar.setOnSeekBarChangeListener(this);
    alphaSeekBar.setOnSeekBarChangeListener(this);
}

@Override
public void onProgressChanged(SeekBar seekBar, int progress, 
            boolean fromUser) {
    int RedValue = redSeekBar.getProgress();
    int GreenValue = greenSeekBar.getProgress();
    int BlueValue = blueSeekBar.getProgress();
    int AlphaValue = alphaSeekBar.getProgress();

    argb(AlphaValue, RedValue, GreenValue, BlueValue);

    colorView.setBackgroundColor(colorValue);

    String rgbValue = Integer.toString(progress);

    colorTextView.setText(rgbValue);

}
@Override 
public void onStartTrackingTouch(SeekBar seekBar) {
}
@Override
public void onStopTrackingTouch(SeekBar seekBar){
}

public static int argb (int alpha, int red, int green, int blue){
    return colorValue;

}

}

Foi útil?

Solução

Your colorValue is always 0!

Replace argb(AlphaValue, RedValue, GreenValue, BlueValue);

by colorValue = argb(AlphaValue, RedValue, GreenValue, BlueValue);

EDIT:

I just realized now: you argb method does nothing! You don't make proper use of any parameter!

Replace it by:

public int argb (int alpha, int red, int green, int blue) {
    return Color.argb(alpha, red, green, blue);
}
Licenciado em: CC-BY-SA com atribuição
Não afiliado a StackOverflow
scroll top