【问题标题】:How to change keyboard layout by swipe left or right space key in custom keyboard如何通过在自定义键盘中向左或向右滑动空格键来更改键盘布局
【发布时间】:2017-01-05 02:21:33
【问题描述】:

我做了一个安卓custom keyboard

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

我该怎么做?

我使用了下面的课程:

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

【问题讨论】:

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


    【解决方案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;}
    

    【讨论】:

    • 喜玛尼。 tnx 为您解答。但我想看到一个完整的样本或完整的答案。我尝试这样做,但我无法解决这个问题。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2016-04-04
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2012-12-20
    • 2018-02-01
    相关资源
    最近更新 更多