Код: Выделить всё
import android.content.Context;
import android.graphics.Canvas;
import android.graphics.Paint;
import android.graphics.Paint.Style;
import android.view.MotionEvent;
import android.view.View;
public class MyView extends View {
private boolean drawTestText = false;
public MyView(Context context) {
super(context);
// TODO Auto-generated constructor stub
}
@Override
public void draw(Canvas canvas) {
// TODO Auto-generated method stub
super.draw(canvas);
Paint background = new Paint();
background.setColor(getResources().getColor(R.color.background));
canvas.drawRect(0, 0, getWidth(), getHeight(), background);
if(drawTestText){
Paint foreground = new Paint(Paint.ANTI_ALIAS_FLAG);
foreground.setColor(getResources().getColor(R.color.foreground));
foreground.setStyle(Style.FILL);
canvas.drawText("Test", getWidth()/10, getHeight()/10, foreground);
}
}
@Override
public boolean onTouchEvent(MotionEvent event) {
drawTestText = true;
invalidate();
return super.onTouchEvent(event);
}
}