0

我试图弄清楚如何使用来自http://developer.android.com/reference/android/graphics/Color.html的 argb 方法。

我已经多次阅读它,但我仍然无法让这个应用程序正常工作。我试图让 View 小部件显示通过移动 4 个滑块产生的颜色,但无论我将滑块放在哪里都不会显示颜色。我认为 argb 方法会返回一个值colorValue,我可以将其用作颜色吗?任何建议,将不胜感激!

我的主要课程如下所示:

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;

}

}

4

1 回答 1

1

colorValue永远是0!

代替argb(AlphaValue, RedValue, GreenValue, BlueValue);

经过colorValue = argb(AlphaValue, RedValue, GreenValue, BlueValue);

编辑:

我现在才意识到:你argb的方法什么都不做!您没有正确使用任何参数!

将其替换为:

public int argb (int alpha, int red, int green, int blue) {
    return Color.argb(alpha, red, green, blue);
}
于 2014-03-10T00:11:16.447 回答