我正在尝试通过 android 中的软键盘在画布上书写。
我的问题是如何显示软键盘并处理它在画布上生成的事件。我的代码是:
public class DrawView extends View {
Paint paint = new Paint();
private static final String LOGID = "MxView";
String message = "No key pressed yet.";
DrawView(Context context) {
super(context);
setFocusable(true);
}
@Override
protected void onDraw(Canvas canvas) {
canvas.drawText(message, 5, 20, paint);
}
@Override
public boolean onKeyDown(int keyCode, KeyEvent ev) {
switch(keyCode) {
case KeyEvent.KEYCODE_ENTER:
message = "Key is Enter!";
Log.i(LOGID, message);
break;
case KeyEvent.KEYCODE_E:
message = "Key is E!";
Log.i(LOGID, message);
break;
default:
return false;
}
invalidate();
return true;
}
}