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

故事扮演 提交于 2019-12-01 14:31:47

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