Question

I am creating an webview and I need to force the softkeyboard when any input is focused in the webpage.

I have tried many things that I found and nothing seems to work.

I have tried: 1)

InputMethodManager imm = (InputMethodManager) getApplicationContext().getSystemService(Context.INPUT_METHOD_SERVICE); 
 imm.toggleSoftInput(InputMethodManager.SHOW_FORCED, 0);

2)

webView.requestFocus(View.FOCUS_DOWN);
 webView.setOnTouchListener(new View.OnTouchListener()
   {
    @Override
     public boolean onTouch(View v, MotionEvent event)
    {
      switch (event.getAction())
      {
        case MotionEvent.ACTION_DOWN:
        case MotionEvent.ACTION_UP:
            if (!v.hasFocus())
            {
                v.requestFocus();
            }
            break;
       }
      return false;
    }
   });

And some other things.

I managed to make it work on a samsung with root but in my nexus 7 also with root i can't.

Any help would be apreciated. Thx

Was it helpful?

Solution

You could detect if there is a keyboard present, and if not show softkeyboard for the needed view/item

sample code:

if (getResources().getConfiguration().keyboard == 0)
{
     InputMethodManager imm = (InputMethodManager) getSystemService(Context.INPUT_METHOD_SERVICE); 
     imm.showSoftInput(** view/item **, InputMethodManager.SHOW_IMPLICIT); 
}
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top