如何在 onSwipe 方法中更改键盘布局?
How to change keyboard layout in onSwipe method?
我想知道如何在 onSwipe
方法中更改键盘布局。
我有 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
}
我想知道如何在 onSwipe
方法中更改键盘布局。
我有 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
}