Android:表情符号作为自定义键盘上的 keyLabel?

Android: emoji as keyLabel on custom keyboard?

我正在开发自定义键盘。但是对于表情符号,我无法将 unicode 表情符号字符设置为 android:keyLabel。我不想使用android:keyIcon.

\uxxxx 不适用于 U+10000 及更高版本。表情符号从 U+1F600 开始。那么如何更改此代码跨度以使用表情符号作为 keyLabel?

<Row>
  <Key android:codes="-100" android:keyLabel="\u1F600"/>
  ... 
</Row>

我知道,这行不通。那么是否可以在不使用 keyIcon 的情况下做同样的事情? 感谢帮助。

你让视图看到:

<resources>
    <array
        name="emoji_nature"
        format="string"
    >
        <!-- <item>1f415</item> -->
        <item>1f436</item>
        <item>1f429</item>

这是在 values 文件夹和

中定义的表情符号 unidcode

这个资源数组用于xml/emoji_nature.xml

代码:

<Keyboard
    xmlns:latin="http://schemas.android.com/apk/res-auto"
    latin:keyWidth="@fraction/config_emoji_keyboard_key_width"
    latin:keyLetterSize="90%p"
    latin:keyLabelSize="60%p"
    latin:rowHeight="@fraction/config_emoji_keyboard_row_height"
>
    <GridRows
        latin:textsArray="@array/emoji_nature"
        latin:keyLabelFlags="fontNormal"
        latin:backgroundType="empty" />
</Keyboard>

第二个解决方案

更改代码 SoftKeyboard.java

private void handleCharacter(int primaryCode, int[] keyCodes) {
        if (getCurrentInputConnection() == null) {
            return;
        }
        if (isInputViewShown()) {
            if (mInputView.isShifted()) {
                primaryCode = Character.toUpperCase(primaryCode);
            }
        }

        getCurrentInputConnection().commitText(String.valueOf(Character.toChars(primaryCode)), 1);



    }

谢谢酷,享受解决问题