gpt4 book ai didi

android - 开发软键盘 - 如何切换 View /服务?

转载 作者:行者123 更新时间:2023-11-30 02:27:58 25 4
gpt4 key购买 nike

我目前使用 InputMethodService 开发了一个软键盘。

它目前创建了一个功能性的 QWERTY 键盘:

public class KeyboardIME extends InputMethodService
implements KeyboardView.OnKeyboardActionListener {

private KeyboardView kbv;
private Keyboard keyboard;


@Override
public void onKey(int primaryCode, int[] keyCodes) {
InputConnection ic = getCurrentInputConnection();
playClick(primaryCode);
switch(primaryCode)
{
case Keyboard.KEYCODE_DELETE :
ic.deleteSurroundingText(1, 0);
break;
case Keyboard.KEYCODE_SHIFT:
caps = !caps;
keyboard.setShifted(caps);
kv.invalidateAllKeys();
break;
case Keyboard.KEYCODE_DONE:
ic.sendKeyEvent(new KeyEvent(KeyEvent.ACTION_DOWN,
KeyEvent.KEYCODE_ENTER));
break;
default:
String codeText = (String) String.valueOf(primaryCode);
char code = (char)primaryCode;

if(Character.isLetter(code) )
{
if(caps)
{
code = Character.toUpperCase(code);
}
}
else if (Integer.valueOf(codeText)==3890)
{
System.out.println("Testing to see if I can make a switch here..");
break;
}
else {
ic.commitText(String.valueOf(code), 1);
break;
}
}





@Override
public View onCreateInputView() {


kbv = (KeyboardView) getLayoutInflater().inflate(R.layout.keyboard, null);
keyboard = new Keyboard(this, R.xml.qwerty);
kbv.setKeyboard(keyboard);
kbv.setOnKeyboardActionListener(this);

return kbv;

}

我在键盘上有一个按钮,当用户按下它时,我希望它变成“不同的键盘”——即切换到不同的 View 。我希望这个其他键盘上有表情符号。但不知道如何进行此切换。

谁能给我一些提示、解决方案或一些我可以阅读以理解这一点的文档?

最佳答案

您可以在 onCreateInputView 方法上扩充布局。

@Override public View onCreateInputView() {

    View view = getLayoutInflater().inflate(R.layout.activity_main, null);
yourLayout = (LinearLayout) view.findViewById(R.id.layout);
return view;


}

然后您可以创建更多键盘并设置可见性。

键盘数

kv = (KeyboardView) getLayoutInflater().inflate(R.layout.keyboard, null);

            keyboard = new Keyboard(mContext, R.layout.nums);
kv.setKeyboard(keyboard);
kv.setOnKeyboardActionListener(onKeyboardActionListener);

键盘 qwerty

kv2 = (KeyboardView) getLayoutInflater().inflate(R.layout.keyboard, null);

            keyboard2 = new Keyboard(mContext, R.layout.qwerty);
kv2.setKeyboard(keyboard);
kv2.setOnKeyboardActionListener(onKeyboardActionListener);

关于android - 开发软键盘 - 如何切换 View /服务?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27657605/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com