Hãy thử điều này, Tôi đã thực hiện nó và nó hoạt động Greate cho tôi.
public void onClick(View view){
switch (view.getId()){
case R.id.colorRedBtn:
//Toast.makeText(getApplicationContext(), "Red", Toast.LENGTH_SHORT).show();
currentPaint = new Paint();
currentPaint.setColor(0xFFFF0000);
currentPaint.setDither(true);
currentPaint.setStyle(Paint.Style.STROKE);
currentPaint.setStrokeJoin(Paint.Join.ROUND);
currentPaint.setStrokeCap(Paint.Cap.ROUND);
currentPaint.setStrokeWidth(3);
break;
case R.id.colorBlueBtn:
//Toast.makeText(getApplicationContext(), "Green", Toast.LENGTH_SHORT).show();
currentPaint = new Paint();
currentPaint.setColor(0xFF00FF00);
currentPaint.setDither(true);
currentPaint.setStyle(Paint.Style.STROKE);
currentPaint.setStrokeJoin(Paint.Join.ROUND);
currentPaint.setStrokeCap(Paint.Cap.ROUND);
currentPaint.setStrokeWidth(3);
break;
case R.id.colorGreenBtn:
//Toast.makeText(getApplicationContext(), "Blue", Toast.LENGTH_SHORT).show();
currentPaint = new Paint();
currentPaint.setColor(0xFF0000FF);
currentPaint.setDither(true);
currentPaint.setStyle(Paint.Style.STROKE);
currentPaint.setStrokeJoin(Paint.Join.ROUND);
currentPaint.setStrokeCap(Paint.Cap.ROUND);
currentPaint.setStrokeWidth(3);
break;
case R.id.colorBlackBtn:
//Toast.makeText(getApplicationContext(), "Black", Toast.LENGTH_SHORT).show();
currentPaint = new Paint();
currentPaint.setColor(0xFF000000);
currentPaint.setDither(true);
currentPaint.setStyle(Paint.Style.STROKE);
currentPaint.setStrokeJoin(Paint.Join.ROUND);
currentPaint.setStrokeCap(Paint.Cap.ROUND);
currentPaint.setStrokeWidth(3);
break;
}
}
Hy vọng điều này sẽ giúp bạn. Tận hưởng.
Nguồn
2011-11-22 09:44:12
Bạn có thể tạo ArrayList của đối tượng Sơn và có thể đặt màu của đường kẻ bằng cách khởi tạo đối tượng Sơn mới trên mỗi lần nhấp vào Nút. –