Reputation: 522
I had tried this out. And it works fine with Samsung tablet.
On Page 1_4.html i have to hide keypad and on 2.html I Have to show keypad.
Both on textbox click inside webview
NOTE: Android Activity is Same.
I'm calling this code on
webView.setOnTouchListener
if (value.equals("1") || value.equals("4")) {
getWindow().setFlags(WindowManager.LayoutParams.FLAG_ALT_FOCUSABLE_IM,WindowManager.LayoutParams.FLAG_ALT_FOCUSABLE_IM);
getWindow().setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_STATE_ALWAYS_HIDDEN);
} else if(value.equals("2")) {
getWindow().clearFlags( WindowManager.LayoutParams.FLAG_ALT_FOCUSABLE_IM);
}
But its not working in any mobile phones. It gives me Warning
W/InputMethodManager(25060): startInputInner : InputBindResult == null
I have google it. But didn't find anything useful.
What should I do now? Any help will be Appreciated.
Upvotes: 0
Views: 1170
Reputation: 1069
To open keypad try this
webview.postDelayed(new Runnable() {
@Override
public void run() {
InputMethodManager keyboard = (InputMethodManager)
MainActivity.this.getSystemService(Context.INPUT_METHOD_SERVICE);
keyboard.showSoftInput(webview, 0);
}
},100);
To close keypad try this
InputMethodManager inputMethodManager = (InputMethodManager)MainActivity.this.getSystemService(Activity.INPUT_METHOD_SERVICE);
inputMethodManager.hideSoftInputFromWindow(MainActivity.this.getCurrentFocus().getWindowToken(), 0);
Upvotes: 2
Reputation: 636
try this code : This is working on all devices.
try
{
if(isopen)
{
// to hide keyboard
InputMethodManager inputMethodManager = (InputMethodManager)context.getSystemService(Activity.INPUT_METHOD_SERVICE);
inputMethodManager.hideSoftInputFromWindow(activity.getCurrentFocus().getWindowToken(), 0);
}else{
// to open keyboard
InputMethodManager inputMethodManager=(InputMethodManager)getSystemService(Context.INPUT_METHOD_SERVICE);
inputMethodManager.toggleSoftInputFromWindow(linearLayout.getApplicationWindowToken(), InputMethodManager.SHOW_FORCED, 0);
}
}
catch (NullPointerException e)
{
}
catch (Exception e)
{
}
Upvotes: 0