0

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.

Virus721
  • 8,061
  • 12
  • 67
  • 123

1 Answers1

1

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()
user229044
  • 232,980
  • 40
  • 330
  • 338
Ruchir Baronia
  • 7,406
  • 5
  • 48
  • 83
  • Thanks for your help, but I tried this way as well as several other variants (toggleSoftInput, showSoftInput, etc). It doesn't work for several people it seems. – Virus721 Dec 10 '15 at 09:08
  • @Virus721 I think I have a solution for you. Try adding this: `yourEditText.requestFocus();`. It should probably work now! – Ruchir Baronia Dec 10 '15 at 09:13
  • Yes using request focus works, thank you. But I also need to add : `dummyTextView.setFocusable(true); dummyTextView.setFocusableInTouchMode(true);` as stated in this answer : http://stackoverflow.com/questions/9311563/show-software-keyboard-without-edittext Please add this to your answer. Unfortunately I can't replace the text edit by my custom drawing view, or this code no longer works. I guess i will have to keep a hidden input somewhere. This is dirty and i'm surprised that android does not provide a way to do this easily and cleanly. – Virus721 Dec 10 '15 at 09:19
  • @Virus721 Yes, it is a bad way to do this! – Ruchir Baronia Dec 10 '15 at 09:20
  • Also this is not working if the edit text is not visible or if we're in landscape mode. – Virus721 Dec 10 '15 at 09:41
  • Not visible...? When do you make it not visible? – Ruchir Baronia Dec 10 '15 at 09:41
  • I don't want to show this edittext, so I change its visibility in the XML, but this causes this way of showing the keyboard not to work anymore. – Virus721 Dec 10 '15 at 09:57
  • Then why do you want to show keyboard in the first place? – Ruchir Baronia Dec 10 '15 at 10:00