使用Android的argb方法存在问题

时间:2014-03-10 00:06:12

标签: java android argb android-seekbar

我试图弄清楚如何使用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;

}

}

1 个答案:

答案 0 :(得分: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);
}