如何通过在自定义键盘中向左或向右滑动空格键来更改键盘布局 [英] How to change keyboard layout by swipe left or right space key in custom keyboard

查看:246
本文介绍了如何通过在自定义键盘中向左或向右滑动空格键来更改键盘布局的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我制作了一个Android custom keyboard.

I made an android custom keyboard.

我想在键盘上的Space key上滑动以更改键盘布局以显示下一种语言布局.

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

我该怎么做?

我使用了波纹管课程:

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

推荐答案

您可以通过覆盖touchEvent这样来实现:

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

这篇关于如何通过在自定义键盘中向左或向右滑动空格键来更改键盘布局的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆