【发布时间】:2020-07-05 12:14:55
【问题描述】:
我想将颜色发送到另一个活动
我触摸 ImageView 以获取颜色并在复选框上显示 setBackgroundColor
public boolean onTouch(View view, MotionEvent motionEvent) {
if (motionEvent.getAction() == MotionEvent.ACTION_DOWN || motionEvent.getAction() == MotionEvent.ACTION_MOVE) {
counter++;
bitmap = mImageView.getDrawingCache();
int pixel = bitmap.getPixel((int) motionEvent.getX(), (int) motionEvent.getY());
int r = Color.red(pixel);
int g = Color.green(pixel);
int b = Color.blue(pixel);
if (counter == 1) {
checkBox1.setBackgroundColor(Color.rgb(r, g, b));
checkBox1.setText("R:" + r + " G:" + g + " B:" + b);
} else if (counter == 2) {
checkBox2.setBackgroundColor(Color.rgb(r, g, b));
checkBox2.setText("R:" + r + " G:" + g + " B:" + b);
} else if (counter == 3) {
checkBox3.setBackgroundColor(Color.rgb(r, g, b));
checkBox3.setText("R:" + r + " G:" + g + " B:" + b);
}
}
return true;
}
然后我想从复选框中选择一种或多种颜色并发送到 Main2activity 并显示在 TextView 上
mSave.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
Intent intent = new Intent(Main3Activity.this,Main4Activity.class);
startActivity(intent);
}
});
}
【问题讨论】: