问题
I am creating a Bhutanese keyboard for an android App. I am using unicode. However, I am getting error messages when I try to run the app that say "error parsing keycode", and the letters do not show up when they are pressed.
Here is a sample of the keyboard xml file:
<?xml version="1.0" encoding="utf-8"?>
<Keyboard xmlns:android="http://schemas.android.com/apk/res/android"
android:keyWidth="10%p"
android:horizontalGap="0px"
android:verticalGap="0px"
android:keyHeight="60dp">
<Row>
<Key android:codes="U+0F09" android:keyLabel="༉" android:keyEdgeFlags="left"/>
<Key android:codes="U+0F21" android:keyLabel="༡"/>
<Key android:codes="U+0F22" android:keyLabel="༢"/>
<Key android:codes="U+0F23" android:keyLabel="༣"/>
<Key android:codes="U+0F24" android:keyLabel="༤"/>
<Key android:codes="U+0F25" android:keyLabel="༥"/>
<Key android:codes="U+0F26" android:keyLabel="༦"/>
<Key android:codes="U+0F27" android:keyLabel="༧"/>
<Key android:codes="U+0F28" android:keyLabel="༨"/>
<Key android:codes="U+0F29" android:keyLabel="༩"/>
<Key android:codes="U+0F20" android:keyLabel="༠"/>
<Key android:codes="U+0F14" android:keyLabel="༔"/>
<Key android:codes="U+0F0D" android:keyLabel="།"/>
<Key android:codes="U+0F5D" android:keyLabel="ཝ" android:keyEdgeFlags="right"/>
</Row>
My keyboard workded when it was an english keyboard, like this one:
<Key android:codes="113" android:keyLabel="q" android:keyEdgeFlags="left"/>
<Key android:codes="119" android:keyLabel="w"/>
<Key android:codes="101" android:keyLabel="e"/>
<Key android:codes="114" android:keyLabel="r"/>
<Key android:codes="116" android:keyLabel="t"/>
<Key android:codes="121" android:keyLabel="y"/>
<Key android:codes="117" android:keyLabel="u"/>
<Key android:codes="105" android:keyLabel="i"/>
<Key android:codes="111" android:keyLabel="o"/>
<Key android:codes="112" android:keyLabel="p" android:keyEdgeFlags="right"/>
</Row>
Am I not supposed to use unicode for a custom android keyboard? Or if I can, what can I do to make it work?
回答1:
To fix the parse error you can either:
- replace "U+0F09" with the decimal (3849) value of the Unicode.
- leave the android code out. The code should be auto generated based on the character in keyLabel. I've tested this with English and Spanish characters.
来源:https://stackoverflow.com/questions/48876029/using-unicode-for-a-custom-android-keyboard