下面列出了android.view.inputmethod.InputMethodManager#hideSoftInputFromWindow ( ) 实例代码,或者点击链接到github查看源代码,也可以在右侧发表评论。
/**
* Navigate to the new page
*
* @param url to load
*/
private void navigate(final String url) {
InputMethodManager imm = (InputMethodManager)this.cordova.getActivity().getSystemService(Context.INPUT_METHOD_SERVICE);
imm.hideSoftInputFromWindow(edittext.getWindowToken(), 0);
this.cordova.getActivity().runOnUiThread(new Runnable() {
public void run() {
if (!url.startsWith("http") && !url.startsWith("file:")) {
InAppBrowser.this.inAppWebView.loadUrl("http://" + url);
} else {
InAppBrowser.this.inAppWebView.loadUrl(url);
}
InAppBrowser.this.inAppWebView.requestFocus();
}
});
}
public LuaValue hideKeyboard(U target, Varargs varargs) {
View view = target.getView();
if (view == null) {
return this;
}
Context context = view.getContext();
if (context instanceof Activity) {
View v = ((Activity) context).getCurrentFocus();
if (v != null) {
IBinder token = v.getWindowToken();
if (token != null) {
InputMethodManager im = (InputMethodManager) context.getSystemService
(Context.INPUT_METHOD_SERVICE);
im.hideSoftInputFromWindow(token, InputMethodManager.HIDE_NOT_ALWAYS);
}
}
}
return this;
}
@Override
public void onResume() {
super.onResume();
InputMethodManager inputMethodManager =
(InputMethodManager) getActivity().getSystemService(INPUT_METHOD_SERVICE);
if (getActivity().getCurrentFocus() != null) {
inputMethodManager.hideSoftInputFromWindow(
getActivity().getCurrentFocus().getWindowToken(), 0);
}
}
public void onFocusChange(View view, boolean isFocused) {
switch (view.getId()) {
case R.id.startDateEditText:
case R.id.dueDateEditText:
if (isFocused) {
final InputMethodManager imm = (InputMethodManager) getActivity().getSystemService(Context.INPUT_METHOD_SERVICE);
imm.hideSoftInputFromWindow(view.getWindowToken(), 0);
}
break;
}
}
@OnTrigger(ClearFocusEvent.class)
static void clearFocus(
ComponentContext c, @State AtomicReference<EditTextWithEventHandlers> mountedView) {
EditTextWithEventHandlers eventHandler = mountedView.get();
if (eventHandler != null) {
eventHandler.clearFocus();
InputMethodManager imm =
(InputMethodManager) c.getAndroidContext().getSystemService(Context.INPUT_METHOD_SERVICE);
imm.hideSoftInputFromWindow(eventHandler.getWindowToken(), 0);
}
}
@Override
public boolean onKeyDown(int keyCode, KeyEvent event)
{
if(boundKeyCodes.contains(keyCode))
{
if (keyCode == KeyEvent.KEYCODE_VOLUME_DOWN) {
this.loadUrl("javascript:cordova.fireDocumentEvent('volumedownbutton');");
return true;
}
// If volumeup key
else if (keyCode == KeyEvent.KEYCODE_VOLUME_UP) {
this.loadUrl("javascript:cordova.fireDocumentEvent('volumeupbutton');");
return true;
}
else
{
return super.onKeyDown(keyCode, event);
}
}
else if(keyCode == KeyEvent.KEYCODE_BACK)
{
return !(this.startOfHistory()) || isButtonPlumbedToJs(KeyEvent.KEYCODE_BACK);
}
else if(keyCode == KeyEvent.KEYCODE_MENU)
{
//How did we get here? Is there a childView?
View childView = this.getFocusedChild();
if(childView != null)
{
//Make sure we close the keyboard if it's present
InputMethodManager imm = (InputMethodManager) cordova.getActivity().getSystemService(Context.INPUT_METHOD_SERVICE);
imm.hideSoftInputFromWindow(childView.getWindowToken(), 0);
cordova.getActivity().openOptionsMenu();
return true;
} else {
return super.onKeyDown(keyCode, event);
}
}
return super.onKeyDown(keyCode, event);
}
/**
* 关闭软键盘
*/
public static void closeSoftKeyboard(Context context) {
InputMethodManager inputMethodManager = (InputMethodManager) context.getSystemService(Context.INPUT_METHOD_SERVICE);
if (inputMethodManager != null && ((Activity) context).getCurrentFocus() != null) {
inputMethodManager.hideSoftInputFromWindow(((Activity) context).getCurrentFocus()
.getWindowToken(), InputMethodManager.HIDE_NOT_ALWAYS);
}
}
/**
* Hide the soft input.
*
* @param view The view.
*/
public static void hideSoftInput(@NonNull final View view) {
InputMethodManager imm =
(InputMethodManager) Utils.getApp().getSystemService(Context.INPUT_METHOD_SERVICE);
if (imm == null) return;
imm.hideSoftInputFromWindow(view.getWindowToken(), 0);
}
/**
* Hides the soft keyboard.
*
* @param activity The reference of the activity displaying the keyboard.
*/
public static void hide(@NonNull final Activity activity) {
final InputMethodManager iManager = (InputMethodManager) activity.
getSystemService(Context.INPUT_METHOD_SERVICE);
final View view = activity.getCurrentFocus();
if (view != null && iManager != null) {
iManager.hideSoftInputFromWindow(view.getWindowToken(), 0);
}
}
@Override
public void onClick(View v) {
if (!validate()) {
return;
}
SharedPreferences sharedPref = getActivity().getPreferences(Context.MODE_PRIVATE);
SharedPreferences.Editor editor = sharedPref.edit();
editor.putString("email", email.getText().toString());
editor.putString("commenterName", commenterName.getText().toString());
editor.putString("commenterUrl", commenterUrl.getText().toString());
editor.commit();
MakeCommentRequest makeCommentRequest = new MakeCommentRequest();
makeCommentRequest.setPostId(postId);
makeCommentRequest.setEmail(email.getText().toString());
makeCommentRequest.setCommentUrl(commenterUrl.getText().toString());
makeCommentRequest.setCommentName(commenterName.getText().toString());
makeCommentRequest.setCommentBody(commentBody.getText().toString());
makeCommentRequest.setCommentId(commentId);
v.setEnabled(false);
email.clearFocus();
commenterName.clearFocus();
commenterUrl.clearFocus();
commentBody.clearFocus();
InputMethodManager imm = (InputMethodManager) getActivity().getSystemService(Context.INPUT_METHOD_SERVICE);
imm.hideSoftInputFromWindow(commentBody.getWindowToken(), 0);
((BaseFragmentActivity) getActivity()).onPreExecute(getResources().getString(R.string.posting_comment));
spiceManager.execute(makeCommentRequest, new MakeCommentListener());
}
/**
* This method is used to hide a keyboard after a user has
* finished typing the url.
*/
public static void hideKeyboard(Activity activity,
IBinder windowToken) {
InputMethodManager mgr =
(InputMethodManager) activity.getSystemService
(Context.INPUT_METHOD_SERVICE);
mgr.hideSoftInputFromWindow(windowToken, 0);
}
/**
* 隐藏软键盘
*/
public static void close(View view) {
try {
InputMethodManager imm = (InputMethodManager) view.getContext()
.getSystemService(Context.INPUT_METHOD_SERVICE);
if (imm != null) {
imm.hideSoftInputFromWindow(view.getWindowToken(), 0);
}
} catch (Exception e) {
e.printStackTrace();
}
}
@Override
public void setFocus(Context context) {
// Hide the soft keyboard if it's showing.
InputMethodManager inputManager =
(InputMethodManager)context.getSystemService(Context.INPUT_METHOD_SERVICE);
inputManager.hideSoftInputFromWindow(this.getWindowToken(), 0);
}
public void hideKeyBoard() {
InputMethodManager imm = (InputMethodManager) getContext()
.getSystemService(Context.INPUT_METHOD_SERVICE);
imm.hideSoftInputFromWindow(lastEditText.getWindowToken(), 0);
}
protected static void hideKeyboard(@NonNull Context context, @NonNull View view) {
InputMethodManager imm = (InputMethodManager) context.getSystemService(Activity.INPUT_METHOD_SERVICE);
imm.hideSoftInputFromWindow(view.getWindowToken(), 0);
}
private void hideKeyboard(){
if(ettEditText != null && !isInEditMode()) {
InputMethodManager imm = (InputMethodManager) getContext().getApplicationContext().getSystemService(Context.INPUT_METHOD_SERVICE);
imm.hideSoftInputFromWindow(ettEditText.getWindowToken(), InputMethodManager.HIDE_IMPLICIT_ONLY);
}
}
@Override
public void dismissKeyboard() {
InputMethodManager imm = (InputMethodManager) getContext().getSystemService(Activity.INPUT_METHOD_SERVICE);
imm.hideSoftInputFromWindow(getActivity().getCurrentFocus().getWindowToken(), 0);
}
public static void hideKeyboard(@NonNull View view) {
InputMethodManager inputManager = (InputMethodManager) view.getContext().getSystemService(Context.INPUT_METHOD_SERVICE);
inputManager.hideSoftInputFromWindow(view.getWindowToken(), 0);
}
@Override
public void onDestroy() {
InputMethodManager imm = (InputMethodManager) getContext()
.getSystemService(Context.INPUT_METHOD_SERVICE);
imm.hideSoftInputFromWindow(getView().getWindowToken(), 0);
}
public void hideKeyboard(Context context, IBinder windowToken) {
InputMethodManager mgr = (InputMethodManager) context.getSystemService(Context.INPUT_METHOD_SERVICE);
mgr.hideSoftInputFromWindow(windowToken, 0);
}