How to show the keyboard in PopupWindow?

I use the PopupWindow class and on PopupWindow I have one EditText , my problem is that when PopupWindow is visible and I click on EditText , the soft keyboard is not visible at this time and I can not enter Input. Can someone tell me how to solve this problem?

+4
source share
4 answers

When you create a new PopupWindow , use another constructor method, you must set focusable = true; only the display can be focused, a soft keyboard will appear.

 public PopupWindow(View contentView, int width, int height, boolean focusable) {} 

Set to false by default

+14
source

Took a little to understand, but here you go:

When creating a pop-up window, I had to set a text field (Edittext) to force the soft keyboard to open when receiving focus.

  txtBox.setOnFocusChangeListener(new OnFocusChangeListener() { public void onFocusChange(View v, boolean hasFocus) { if (hasFocus == true){ InputMethodManager inputMgr = (InputMethodManager)getSystemService(Context.INPUT_METHOD_SERVICE); inputMgr.toggleSoftInput(InputMethodManager.SHOW_FORCED, 0); inputMgr.showSoftInput(v, InputMethodManager.SHOW_IMPLICIT); } } }); txtBox.requestFocus(); 
+5
source

Add this code popupWindow.setFocusable (true);

+4
source

It worked for me.

 editText.setOnFocusChangeListener(new View.OnFocusChangeListener() { @Override public void onFocusChange(final View v, final boolean hasFocus) { if (hasFocus && editText.isEnabled() && editText.isFocusable()) { editText.post(new Runnable() { @Override public void run() { final InputMethodManager imm =(InputMethodManager)getBaseContext().getSystemService(Context.INPUT_METHOD_SERVICE); imm.showSoftInput(editText,InputMethodManager.SHOW_IMPLICIT); } }); } } }); 
+1
source

All Articles