Created
August 14, 2019 20:36
-
-
Save sssurvey/c1bc88b9c196ca11fc31599e258e2441 to your computer and use it in GitHub Desktop.
hide soft keyboard on Android WebView 1
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function hide_soft_keyboard(input_box) { | |
input_box.addEventListener("click", function() { | |
input_box.blur(); // very important call | |
input_box.focus();// very important call x2 | |
}); | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@Override | |
protected void onCreate(Bundle savedInstanceState) { | |
/* | |
Normal onCreate stuff | |
*/ | |
ExtendedWebView webView = findViewById(R.id.webview_id); | |
WebSettings settings = webView.getSettings(); | |
settings.setJavaScriptEnabled(true); | |
webView.addJavascriptInterface(new MyJavascript(), "_my_javascript"); | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@Override | |
public InputConnection onCreateInputConnection(EditorInfo outAttrs) { | |
hideKeyboard(); | |
return super.onCreateInputConnection(outAttrs); | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
private void hideKeyboard() { | |
post(new Runnable() { | |
@Override | |
public void run() { | |
InputMethodManager imm = (InputMethodManager) getContext() | |
.getSystemService(Context.INPUT_METHOD_SERVICE); | |
if (imm != null) imm.hideSoftInputFromWindow(getRootView().getWindowToken(), 0); | |
} | |
}); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment