我正在做一个填字游戏。理想情况下,我想使用类似下面的代码的功能。但是,我只需要帮助弄清楚如何在屏幕上绘制文本字段,以便用户可以输入他/她的话。这是我到目前为止的代码。我将如何修改此代码以绘制文本字段而不是绘制?感谢任何帮助。
public class Word extends View {
private Paint paint = new Paint();
private Path path = new Path();
public Word(Context context, AttributeSet attrs) {
super(context, attrs);
paint.setAntiAlias(true);
paint.setStrokeWidth(30f);
paint.setColor(Color.GRAY);
paint.setStyle(Paint.Style.STROKE);
paint.setStrokeJoin(Paint.Join.ROUND);
}
@Override
protected void onDraw(Canvas canvas) {
canvas.drawPath(path, paint);
}
@Override
public boolean onTouchEvent(MotionEvent event) {
float eventX = event.getX();
float eventY = event.getY();
switch (event.getAction()) {
case MotionEvent.ACTION_DOWN:
path.moveTo(eventX, eventY);
return true;
case MotionEvent.ACTION_MOVE:
path.lineTo(eventX, eventY);
break;
case MotionEvent.ACTION_UP:
break;
default:
return false;
}
// Schedules a repaint.
invalidate();
return true;
}