我制作了一个机器人custom keyboard
。
我想使用键盘上的Space key
滑动来更改键盘布局以显示下一种语言布局。
我该怎么做?
我用了下面的课:
public class KeyboardIMS extends InputMethodService implements KeyboardView.OnKeyboardActionListener
{ ...}
答案 0 :(得分:1)
您可以通过覆盖touchEvent来执行此操作:
@Override
public boolean onTouchEvent(MotionEvent e) {
float x = e.getX();
float y = e.getY();
switch (e.getAction()) {
case MotionEvent.ACTION_DOWN:
mIsDown = true;
break;
case MotionEvent.ACTION_MOVE:
float dx = x - mPreviousX;
float dy = y - mPreviousY;
// Here you can try to detect the swipe. It will be necessary to
// store more than the previous value to check that the user move constantly in the same direction
detectSwipe(dx, dy);
case MotionEvent.ACTION_UP:
mIsDown = false;
break;
}
mPreviousX = x;
mPreviousY = y;
return true;}