如何通过在自定义键盘中向左或向右滑动空格键来更改键盘布局



我制作了一个android custom keyboard

我想使用在键盘上滑动Space key来改变键盘布局以显示下一个语言布局。

我该怎么做呢?

我使用了下面的class:

public class KeyboardIMS extends InputMethodService implements KeyboardView.OnKeyboardActionListener
{ ...}

你可以这样重写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;}

相关内容

  • 没有找到相关文章

最新更新