【问题标题】:Android's InputMethodService - how to get unicode characters?Android 的 InputMethodService - 如何获取 unicode 字符?
【发布时间】:2015-08-17 14:34:49
【问题描述】:

我正在尝试制作键盘...

int code = 29; // Key code constant: 'A' key. Constant Value: 29 (0x0000001d)
KeyEvent k = new KeyEvent(KeyEvent.ACTION_UP, code);

InputConnection ic = getCurrentInputConnection();
ic.sendKeyEvent(k);

此代码很好地向应用程序发送字母“A”,因为它与代码“29”相关联,从这里http://developer.android.com/reference/android/view/KeyEvent.html

但是如果我想使用 unicode 字符,我该怎么办,比如这里
http://en.wikipedia.org/wiki/List_of_Unicode_characters

【问题讨论】:

  • ic.commitText("ПРЕВЕД МЕДВЕД", 0);

标签: android


【解决方案1】:

如果您正在构建一个键盘应用程序,并且在 xml 中有键盘布局,您可以在另一个 thread 中查看用户 Laurent' 提供的建议:

<Key android:codes="946" android:keyLabel="\u03B2"/> 
<Key android:codes="946" android:keyLabel="&946;"/> 
<Key android:codes="946" android:keyLabel="β"/>  
<!-- Warning, you should use UTF-8 encoding for your project files if you use the third solution -->
<!-- all produce the same key with greek β character (unicode \u03B2, decimal 946) -->

【讨论】:

    【解决方案2】:

    请查看softkeyboard 示例代码。

    如果您正在开发新的键盘(例如用于任何其他语言),请将 android:code 属性值更改为您希望键盘输出的 unicode 值。 这很好用,我认为您可以在同一个 softkeyboard 项目中对其进行测试。

    【讨论】:

      猜你喜欢
      • 2012-04-27
      • 2014-09-27
      • 2011-06-11
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多