如何将自定义InputMethodService添加到Activity? [英] How to add custom InputMethodService to Activity?

本文介绍了如何将自定义InputMethodService添加到Activity?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我决定为我的应用程序创建一个自定义键盘.我知道这不是最好的主意,因为它损害了用户友好性,这就是为什么我要在首选项"中将其设置为可选.

I decided to create a custom keyboard for my application. I know that this is not the best idea, since it's hurting the user friendliness, that's why I will just make it optional in Preferences.

在类public class CustomKeyboard extends InputMethodService implements KeyboardView.OnKeyboardActionListener中完成所有操作之后.我很难将其添加为softInputMethod.我尝试使用InputMethodManager,但是在投射它时得到了不兼容的类型.

After having it all done in a class public class CustomKeyboard extends InputMethodService implements KeyboardView.OnKeyboardActionListener. I struggle to add it as a softInputMethod. I tried with the InputMethodManager but I get incompatible types when casting it.

我发现我可以不通过Service获得它,但是强烈建议不要使用它,并且我需要一个全新的实现.

I found that I can get it w/o the Service but it is highly unrecommended and I would need a whole new implementation.

理想情况下,我会将其用于应用程序中的EditText命令行.因此,直接绑定它也可以完成这项工作.

Ideally, I would use it for the EditText command line in the app. So a direct binding to it would also do the job.

隐藏系统输入法后,如何使该输入服务成为默认输入法?

After hiding the system input method, how to make this input service the default one?

谢谢.



P.S.很抱歉,如果有一种显而易见的简便方法,但是我刚刚过渡到Android,但我仍在学习.



P.S. If there is an obvious easy way to do this, I am sorry, but I just made the transition to Android and I am still learning.

推荐答案

在要更改输入法的文本字段上使用android:inputMethod.参见 https://developer.android.com/reference/android/widget/TextView.html#attr_android:inputMethod

Use android:inputMethod on the text field you want to change the input method on. See https://developer.android.com/reference/android/widget/TextView.html#attr_android:inputMethod

您无法为整个设备设置默认输入法,但可以在应用程序中逐字段覆盖它.为活动"或应用程序"主题添加默认输入法应在应用程序中的所有文本视图中覆盖它.

You cannot set a default input method for the entire device, but you can override it on a field by field basis in your app. Adding a default input method for your Activity or Application's theme should override it for all text views in your app.

这篇关于如何将自定义InputMethodService添加到Activity?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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