Virus721
Virus721

Reputation: 8315

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.

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.

Upvotes: 0

Views: 346

Answers (1)

Ruchir Baronia
Ruchir Baronia

Reputation: 7561

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()

Upvotes: 1

Related Questions