How to change keyboard layout by swipe left or right space key in custom keyboard

不打扰是莪最后的温柔 提交于 2019-12-01 12:19:28

问题


I made an android custom keyboard.

I want to use swiping on Space key on the keyboard for changing keyboard layout to show next language layout.

How can i do that?

I used bellow class:

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

回答1:


You can do this by override touchEvent like this :

@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;}


来源:https://stackoverflow.com/questions/39199703/how-to-change-keyboard-layout-by-swipe-left-or-right-space-key-in-custom-keyboar

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!