创建与每个键多/备选字符SoftKeyboard [英] Creating a SoftKeyboard with Multiple/Alternate characters per key

查看:213
本文介绍了创建与每个键多/备选字符SoftKeyboard的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经按照有关的 developer.android.com 的例子。 COM /资源/文章/创建-输入method.html> ,并使用了与的 SoftKeyboard 示例应用程序。这些合作多过关于建立简单的键盘的足够的信息。

I've followed the examples on developer.android.com regarding Input Methods and played with the SoftKeyboard sample application. These together give more than enough information regarding the creation of simple keyboard.

我不能在API中看到的是每个键是可在标准键盘(LatinIME键盘)创建备用/多个字符的能力。

What I can't see in the API is the ability to create alternate / multiple characters per key which is available on the standard Keyboard (LatinIME Keyboard).

上图是对A键长preSS的结果。当你长时间preSS的关键是可能的填充弹出用替代字符。

The above image is the result of a long press on the "a" key. When you long press a key it's possible to populate a popup with alternate characters.

也可以给一个弹出提示了一些按键,会提示用户preSS和抓住关键,以获得在弹出菜单中。

It is also possible to give a popup hint on some keys which will prompt the user to press and hold a key in order to get the popup menu.

到目前为止,我还没有发现关于这是如何实现的单一来源,希望有人能够给我一个良好的开端,到那时我会按照内置的键盘的来源$ C ​​$ c和看能不能进行反向工程了。

So far I haven't found a single source of information on how this is achieved, hopefully someone will be able to give me a head start, until then I'll follow the source code of the inbuilt keyboard and see if I can reverse engineer it.

编辑:倘使 developer.android.com 到LatinIME键盘s链路没 T链接到的图片:)实际来源$ C ​​$ C的<一个href="http://www.google.com/$c$csearch#cZwlSNS7aEw/packages/inputmethods/LatinIME/java/src/com/android/inputmethod/latin/LatinIME.java&type=cs">LatinIME.java.

Would help if developer.android.com 's link to the LatinIME Keyboard didn't link to a picture of a Sheep :) Actual source code for LatinIME.java.

编辑2:更多的比什么都重要的参考,这是序列我相信一般长preSS行动经历,以显示在<一个弹出式键盘href="http://www.google.com/$c$csearch#cZwlSNS7aEw/frameworks/base/core/java/android/inputmethodservice/KeyboardView.java">KeyboardView.java:

Edit 2: More as a reference than anything else, this is the sequence I believe a usual longPress action goes through in order to show the popup keyboard in KeyboardView.java:

onTouchEvent()
onModifiedTouchEvent()
mHandkler.handleMessage() with MSG_LONGPRESS
openPopupIfRequired() 
onLongPress()

修改3:

我还没有想通了这一点 - 你如何添加标签建议钥匙?的回答表明,它没有内置到API,实际上我还没有发现codeTO做到这一点。然而在2.3.4(API 10)键盘显示了这个功能正在实施的:

I still haven't figured this out - How do you add label suggestions to keys? An answer suggests it isn't built into the API and indeed I haven't found the codeto do this. However the Keyboard on 2.3.4 (API 10) shows this functionality being implemented:

非常想弄清楚它是如何做它,但它是不是在的OnDraw()的方法,我可以看到任何地方 - 这使我相信它的存在该KeyboardView元素之外编写的。我却无法找到布局用来显示内置的键盘上的KeyboardView元素文件 - 如果有谁知道在哪里可以找到这也许会给我,我需要的线索。

Would very much like to figure out how IT does it but it isn't anywhere in the onDraw() method that I can see - which makes me believe it's being written outside of the KeyboardView element. I can't however find the layout file used to display the KeyboardView element on the inbuilt keyboard - If anyone knows where to find this perhaps that will give me the clue I need.

修改4:感动键preVIEW这里的问题,因为它是稍微偏离主题:

Edit 4: Moved key Preview question here as it's slightly off topic:

如何禁用/自定义软键盘按键preVIEW窗口?

推荐答案

实施备用键弹出:

对于每一个键,你希望有一个弹出式的键盘,你应该定义<一个href="http://developer.android.com/reference/android/inputmethodservice/Keyboard.Key.html#attr_android%3apopupCharacters">popupCharacters和<一href="http://developer.android.com/reference/android/inputmethodservice/Keyboard.Key.html#attr_android%3apopupKeyboard">popupKeyboard:

For each key you wish to have a popup keyboard you should define popupCharacters and popupKeyboard:

/ RES / XML / [键盘]的.xml

<Key android:keyLabel="("
    android:popupKeyboard="@xml/keyboard_popup_template"
    android:popupCharacters="[{&lt;" />

popupKeyboard 是在包含备用键弹出使用键盘的XML重新presentation:

The popupKeyboard is an XML representation of the keyboard used in the popup containing the alternate keys:

/res/xml/keyboard_popup_template.xml

<Keyboard xmlns:android="http://schemas.android.com/apk/res/android"
    android:keyWidth="10%p"
    android:horizontalGap="0px"
    android:verticalGap="0px"
    android:keyHeight="56dp">
</Keyboard>

风格化的备用键弹出:

如果你想改变弹出窗口的布局/样式(默认为<一个href="http://www.google.com/$c$csearch#cZwlSNS7aEw/frameworks/base/core/res/res/layout/keyboard_popup_keyboard.xml">@android:layout/ keyboard_popup_keyboard.xml ),你可以指定一个安卓popupLayout 属性,它指向一个布局文件:

If you want to change the layout/style of the popup (which defaults to @android:layout/ keyboard_popup_keyboard.xml) you can specify a android:popupLayout attribute which points to a layout file:

<android.inputmethodservice.KeyboardView
    android:id="@+id/keyboard"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:layout_alignParentBottom="true"
    android:background="#FF272727"
    android:popupLayout="@layout/keyboard_popup_keyboard" />

的实施,关键preVIEW覆盖:

我已经能够拼凑显示关键previews(不完全重写KeyboardView源$ C ​​$ C)唯一的解决办法是如下:

The only solution I've been able to knock together to show key previews (Without entirely rewriting the KeyboardView source code) is below:

中包装&LT; KeyboardView&gt;在标签的&LT;的FrameLayout&GT; 与乘以keyHeight指定的高度按行的量。在这个标签,我只是创造了一个的LinearLayout保存行,然后LinearLayout中包含有相当于每个指定的%P值的权重TextView中的每一行&LT;关键&GT;

Wrapping the <KeyboardView> tag with a <FrameLayout> with a height specified by multiplying the keyHeight by the amount of rows. Inside this tag I've simply created a LinearLayout to hold rows, then a LinearLayout for each row containing a TextView with a weight equal to the %p value specified for each <Key>:

<TextView android:text="!" style="@style/Custom.Widget.KeyboardKeyOverlay"  android:layout_width="0dp" android:layout_height="wrap_content" android:layout_weight="10"/>

和风格:

<style name="CustomTheme.Widget.KeyboardKeyOverlay">
    <item name="android:background">@android:color/transparent</item>
    <item name="android:textColor">#FFAAAAAA</item>
    <item name="android:paddingRight">6dp</item>
    <item name="android:paddingTop">4dp</item>
    <item name="android:textSize">10sp</item>
    <item name="android:gravity">right</item>
    <item name="android:textStyle">bold</item>
</style>         

这会产生这样的:

Which produces this:

我也不会开心,直到我设法以同样的方式来实现这个作为系统的键盘呢!

I won't be happy until I've managed to implement this in the same way as the System Keyboard does!

这篇关于创建与每个键多/备选字符SoftKeyboard的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆