本文介绍了安卓:非键盘输入法的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试着去创造一个输入法Android版,是不是一个传统的键盘(行对应于不同的字母按键),我无法找到如何做到这一点,因为所有的code例子,有用的资源在SDK使用一个键盘的API和它的内置函数。

Im trying to create an IME for android that is not a traditional keyboard (rows of keys corresponding to the different letters) and I am having trouble finding helpful resources on how to do so since all of the code examples in the SDK use a Keyboard API and it's built in functions.

我设计了输入法的界面在XML文件中,就好像是只需在应用程序中的活动,但我迷失在自己的演示,因为他们的键盘是由不同风格的XML内建简单对象结构。

I've designed the interface of the IME in an XML file as though it were simply an Activity within in application but I'm getting lost in their demos since their Keyboards are simply objects that are built from a different style of XML structure.

如果任何人有一个链接,不使用臣民键盘结构或者可以简单地指导我显示我已经建造到输入法窗口中的用户界面的一个开源项目,我想我可以计算休息了。

If anyone has a link to an open source project that does not use the tradional keyboard structure or could simply guide me to displaying the UI that I've already constructed onto the IME window, I think I can figure the rest out.

如果您需要更多的specfic信息,请随时提出。先谢谢了。

If you need any more specfic information, please feel free to ask.Thanks in advance.

推荐答案

的的样,其实是相同的结构。你需要什么,尽管你不知道它。让我们打破它 - 这里有一个完整的存根作为一个输入法服务,并使用标准的XML键盘:

The SoftKeyboard sample is in fact structured similarly to what you need, though you don’t know it. Let’s break it down — here’s a complete stub to act as an input method service and use the standard XML keyboard:

import android.inputmethodservice.InputMethodService;
import android.inputmethodservice.Keyboard;

public class MyInputMethod extends InputMethodService {
    private Keyboard mKeyboard;

    @Override public void onInitializeInterface() {
        mKeyboard = new Keyboard(this, R.xml.qwerty);
    }

    @Override public View onCreateInputView() {
        mInputView = (KeyboardView) getLayoutInflater().inflate(
                R.layout.input, null);
        mInputView.setKeyboard(mKeyboard);
        return mInputView;
    }
}

请注意这两个XML文档的命名方式。第一, RES / XML / qwerty.xml ,定义布局,使 KeyboardView 类知道如何绘制键盘。

Note that two XML documents are named. The first, res/xml/qwerty.xml, defines the layout so that the KeyboardView class knows how to draw the keyboard.

但它膨胀的布局, RES /布局/ input.xml中,由这个(简体):

But the layout which it inflates, res/layout/input.xml, consists of this (simplified):

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android">
    <android.inputmethodservice.KeyboardView android:id="@+id/keyboard" />
</LinearLayout>

这是所有你需要声明的方式创建一个视图!创建一个独立的查看不是从创建活动多大区别。您没有标准的活动周期,但两者的环境让您接触到XML的布局。所有你需要做的是利用充气,引用您需要任何子视图,然后返回主视图。

This is all you need to declaratively create a view! Creating a stand-alone View isn’t much different from creating an Activity. You don’t have the standard activity lifecycle, but both environments give you access to XML layouts. All you need to do is use the inflater, reference any subviews you need, and then return the main view.

所以希望你能够思考这个后膨胀布局。

So hopefully you’ll be able to inflate your layout after thinking about this.

您甚至不需要使用XML的布局,如果你的布局是很简单的。如果你的输入法可以包含的完全的单一视图中,你可以直接实例化它 onCreateInputView 。下面是一个不使用任何XML完整的存根输入法服务:

You don’t even need to use XML layouts if your layout is simple enough. If your input method can consist entirely of a single view, you can just instantiate it directly in onCreateInputView. Here’s a complete stub input method service that doesn’t use any XML:

public class MyInputMethod extends InputMethodService {
    MyView view;

    @Override
    public View onCreateInputView() {
        return view = new MyView(this);
    }

}

(当然在清单和 RES / XML / method.xml 文件样板仍然存在。)

(Of course the boilerplate in the manifest and res/xml/method.xml files would still be there.)

这篇关于安卓:非键盘输入法的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

07-31 19:58