Android 如何在onSwipe方法中更改键盘布局?

Android 如何在onSwipe方法中更改键盘布局?,android,xml,layout,android-softkeyboard,gesture,Android,Xml,Layout,Android Softkeyboard,Gesture,我想知道如何在onswip方法中更改键盘布局。 我有带字母的qwerty.xml,但我需要数字和符号。 这两组字符位于numeric.xml中 当我向左或向右滑动时,numeric.xml将显示,qwerty.xml将隐藏 如果您需要我的代码的任何部分,请询问 您需要在InputManagerService中更改键盘对象的布局。然后,您需要使所有键无效,以便重新绘制键盘。 像这样: public class MyKeyboard extends InputMethodService imple

我想知道如何在
onswip
方法中更改键盘布局。
我有带字母的
qwerty.xml
,但我需要数字和符号。
这两组字符位于
numeric.xml

当我向左或向右滑动时,
numeric.xml
将显示,
qwerty.xml
将隐藏


如果您需要我的代码的任何部分,请询问

您需要在InputManagerService中更改键盘对象的布局。然后,您需要使所有键无效,以便重新绘制键盘。 像这样:

 public class MyKeyboard extends InputMethodService implements KeyboardView.OnKeyboardActionListener
 {

    private KeyboardView myKeyboardView;
    private Keyboard myKeyboard;

    public View onCreateInputView()
    {

       viewOfKeyboard = (KeyboardView)getLayoutInflater().inflate(R.layout.keyboard1, null);
       theKeyboardLayout = new Keyboard(this, R.xml.keyboardlayout);
       viewOfKeyboard.setKeyboard(theKeyboardLayout);
       viewOfKeyboard.setOnKeyboardActionListener(this);
       return myKeyboardView;
    }

    public void swipeRight()
    {
       if(isQwerty)
       {
         myKeyboard = new Keyboard(this, R.xml.numeric);
         //Creates a new keyboard object.
         myKeyboardView.setKeyboard(myKeyboard);
         //Assigns the new keyboard object to the keyboard view
         myKeyboardView.invalidateAllKeys();
         //Makes android redraw the keyboard view, with the new layout.
         isqwerty = false;
       }
       else
       {
         myKeyboard = new Keyboard(this, R.xml.qwerty); 
         myKeyboardView.setKeyboard(myKeyboard);
         myKeyboardView.invalidateAllKeys();
         isqwerty = true;
       }

       //.........the rest of MyKeyboard's methods     

    }