简体   繁体   English

Android-如何显示自定义键盘

[英]Android - How to show a custom keyboard

I have added a custom Keyboard to my application. 我已经在应用程序中添加了自定义键盘。 It works correctly when using another application that has text inputs . 当使用另一个具有文本输入的应用程序时,它可以正常工作 I have changed the settings / language and input so that it is enabled and also used as default. 我更改了settings / language and input以便启用它并将其用作默认值。

My problem is that I don't know how to show it in my application. 我的问题是我不知道如何在应用程序中显示它。 I have a view where I draw a terminal screen using a canvas. 我有一个视图,可以在其中使用画布绘制终端屏幕。 There is no text input, but yet I do need the keyboard to show up. 没有文本输入,但是我确实需要键盘来显示。

How can I force the keyboard to show up ? 如何强制键盘显示? I saw several ways to do it, using the manifest, using the input method manager, etc... but none worked in my case. 我看到了几种方法,例如使用清单,使用输入法管理器等,但是在我的情况下没有一种方法有效。 Must I focus an input for the keyboard to show up ? 我是否需要集中显示键盘输入? Can't I just show it and hide it whenever I want ? 我是否可以随时显示并隐藏它?

Thank you. 谢谢。

EDIT : Imanaged to show the keyboard by adding a text input and clicking on it. 编辑:我设法通过添加文本输入并单击它来显示键盘。 But I still have no idea how to show it without a text input. 但是我仍然不知道如何在没有文本输入的情况下显示它。

You stated it is already default. 您说它已经是默认值。 So, you can simply make it show up manually: 因此,您可以简单地使其手动显示:

InputMethodManager imm = (InputMethodManager) getSystemService(Context.INPUT_METHOD_SERVICE);
imm.showSoftInput(yourEditText, InputMethodManager.SHOW_IMPLICIT);

To hide it: 隐藏它:

InputMethodManager imm = (InputMethodManager) getSystemService(Context.INPUT_METHOD_SERVICE);
imm.hideSoftInputFromWindow(yourEditText.getWindowToken(), 0);

This way, user doesn't have to click on the text input to make key board show up. 这样,用户不必单击文本输入即可显示键盘。 If this helped, please accept. 如果有帮助,请接受。

EDIT 编辑

You must also request focus: 您还必须要求重点:

yourEditText.requestFocus()

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM