Android: Non-Keyboard IME

I'm trying to create an IME for Android, which is not a traditional keyboard (key strings corresponding to different letters), and I'm having problems finding useful resources, how to do this, since all the code examples in the SDK use keyboard APIs and built-in functions.

I developed the IME interface in the XML file, as if it were just an Activity inside the application, but I am lost in my demo entries, because their Keyboards are just objects that are built from a different style of XML structure.

If someone has a link to an open source project that does not use the traditional keyboard structure or can just lead me to display the user interface that I already built in the IME window, I think I can understand the rest.

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

+6
source share
1 answer

The SoftKeyboard sample is actually structured similar to what you need, although you do not know it. Let's break it - this is a complete stub to act as a service of an input method and use a 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; } } 

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

But the layout he is inflating, 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> 

That's all you need to declaratively create a view! Creating a standalone View not much different than creating an Activity . You do not have a standard activity life cycle, but both environments provide you with access to XML layouts. All you have to do is use the blower, refer to any subheadings you need, and then return the main view.

So, I hope you can inflate your layout by thinking about it.


You don’t even need to use XML layouts if your layout is simple enough. If your input method can consist entirely of one view, you can simply create it directly in onCreateInputView . Heres a complete stub input method that does not use any XML:

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

(Of course, the templates in the manifest and the res/xml/method.xml will still be there.)

+6
source

Source: https://habr.com/ru/post/891175/


All Articles