Why doesn't showSoftInput display a virtual keyboard?

Essentially, I'm trying to show a virtual keyboard and collect input without using a visible EditText or TextView . I understand that toggleSoftInput can be used for this, but I need to use showSoftInput because I want to use TextWatcher to control input. In addition, the engine I use is C ++, so I try to make as little java code as possible, so I avoid .xml files. So here goes ...

 public class GameActivity extends Activity { protected GameView view = null; protected EditText editText; protected void onCreate(Bundle bundle) { super.onCreate(bundle); view = new GameView(this); setContentView(view); editText = new EditText(this); editText.setCursorVisible(false); editText.setFocusable(true); editText.setFocusableInTouchMode(true); } public boolean showKeyboard() { JniApp.log("showKeyboard() in Java invoked!!!"); editText.requestFocus(); editText.requestFocusFromTouch(); InputMethodManager imm = (InputMethodManager) getSystemService(Context.INPUT_METHOD_SERVICE); imm.showSoftInput(editText, InputMethodManager.SHOW_FORCED); } 

Where showKeyboard() is my C ++ call in java. I checked that EditText getting focus, and that is. However, showSoftInput returns false. Any help would be greatly appreciated.

UPDATE: after some debugging, it looks like requestFocus returns true, but the activity still says that view is the current focus.

+4
source share
1 answer

Maybe try using .SHOW_IMPLICIT instead of .SHOW_FORCED?

Have you tried it on other emulators / devices, perhaps in other versions of Android?

0
source

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


All Articles