public class MainActivity extends Activity { SeekBar redBar; SeekBar greenBar; SeekBar blueBar; TextView redView; TextView greenView; TextView blueView; int red; int green; int blue; TextView resultView; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); redBar = (SeekBar) findViewById(R.id.redBar); greenBar = (SeekBar) findViewById(R.id.greenBar); blueBar = (SeekBar) findViewById(R.id.blueBar); redView = (TextView) findViewById(R.id.redView); greenView = (TextView) findViewById(R.id.greenView); blueView = (TextView) findViewById(R.id.blueView); resultView = (TextView) findViewById(R.id.resultView); redBar.setOnSeekBarChangeListener(new OnSeekBarChangeListener() { @Override public void onStopTrackingTouch(SeekBar seekBar) {} @Override public void onStartTrackingTouch(SeekBar seekBar) {} @Override public void onProgressChanged(SeekBar seekBar, int progress, boolean fromUser) { red = redBar.getProgress(); redView.setText("red - "+red); resultView.setBackgroundColor(Color.rgb(red, green, blue)); } }); greenBar.setOnSeekBarChangeListener(new OnSeekBarChangeListener() { @Override public void onStopTrackingTouch(SeekBar seekBar) {} @Override public void onStartTrackingTouch(SeekBar seekBar) {} @Override public void onProgressChanged(SeekBar seekBar, int progress, boolean fromUser) { green = greenBar.getProgress(); greenView.setText("green - "+green); resultView.setBackgroundColor(Color.rgb(red, green, blue)); } }); blueBar.setOnSeekBarChangeListener(new OnSeekBarChangeListener() { @Override public void onStopTrackingTouch(SeekBar seekBar) {} @Override public void onStartTrackingTouch(SeekBar seekBar) {} @Override public void onProgressChanged(SeekBar seekBar, int progress, boolean fromUser) { blue = blueBar.getProgress(); blueView.setText("blue - "+blue); resultView.setBackgroundColor(Color.rgb(red, green, blue)); } }); }
|