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

时间:2016-08-29 06:21:53

标签: android android-softkeyboard android-input-method soft-keyboard

我制作了一个机器人custom keyboard

我想使用键盘上的Space key滑动来更改键盘布局以显示下一种语言布局。

我该怎么做?

我用了下面的课:

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

1 个答案:

答案 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;}