相关疑难解决方法(0)

在Android键盘中每两个键输出一个字符

我正在Android中为Amharic语言设计自定义键盘,但以下内容适用于许多其他非英语语言.

两个或多个键组合转换为一个字符.因此,如果用户键入'S',键盘将输出'ሰ'...如果他们跟着字母'A',则'ሰ'将替换为'ሳ'.

我设法得到一个解决方案,如下所示,通过查看光标前的字符并根据Map检查它.但是,我想知道是否有更简单,更清洁的解决方案.

public void onKey(int primaryCode, int[] keyCodes) {
    InputConnection ic = getCurrentInputConnection();
    HashMap<String, Integer> en_to_am = new HashMap<String, Integer>();
    CharSequence pChar = ic.getTextBeforeCursor(1, 0);
    int outKey = 0;

    //build a hashmap of 'existing character' + 'new key code' = 'output key code'
    en_to_am.put("83", 4656);
    en_to_am.put("?65", 4659);

    try {
        //see if config exists in hashmap for 'existing character' + 'new key code'
        if (en_to_am.get(pChar.toString() + primaryCode) != null) {
            outKey = en_to_am.get(pChar.toString() + primaryCode);
            ic.deleteSurroundingText(1, 0);
        } else { …
Run Code Online (Sandbox Code Playgroud)

java android locale non-latin android-softkeyboard

10
推荐指数
1
解决办法
774
查看次数

标签 统计

android ×1

android-softkeyboard ×1

java ×1

locale ×1

non-latin ×1