我正在構建一個填字遊戲。理想情況下,我想使用類似於下面的代碼的功能。不過,我只需要幫忙弄清楚如何在屏幕上繪製文本字段,以便用戶輸入他/她的單詞。這是我迄今爲止的代碼。我將如何修改此代碼來繪製文本字段而不是繪畫?感謝任何幫助。如何將文本字段繪製到屏幕上
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;
}
Google:'android paint text'let me to http://stackoverflow.com/questions/2655402/android-canvas-drawtext – cYrixmorten