android.view.View.getWindowToken()方法的使用及代码示例

x33g5p2x  于2022-01-17 转载在 其他  
字(6.7k)|赞(0)|评价(0)|浏览(447)

本文整理了Java中android.view.View.getWindowToken()方法的一些代码示例,展示了View.getWindowToken()的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。View.getWindowToken()方法的具体详情如下:
包路径:android.view.View
类名称:View
方法名:getWindowToken

View.getWindowToken介绍

暂无

代码示例

代码示例来源:origin: stackoverflow.com

// Check if no view has focus:
View view = this.getCurrentFocus();
if (view != null) {  
  InputMethodManager imm = (InputMethodManager)getSystemService(Context.INPUT_METHOD_SERVICE);
  imm.hideSoftInputFromWindow(view.getWindowToken(), 0);
}

代码示例来源:origin: stackoverflow.com

public static void hideKeyboardFrom(Context context, View view) {
  InputMethodManager imm = (InputMethodManager) context.getSystemService(Activity.INPUT_METHOD_SERVICE);
  imm.hideSoftInputFromWindow(view.getWindowToken(), 0);
}

代码示例来源:origin: stackoverflow.com

public void hideKeyboard(View view) {
   InputMethodManager inputMethodManager =(InputMethodManager)getSystemService(Activity.INPUT_METHOD_SERVICE);
   inputMethodManager.hideSoftInputFromWindow(view.getWindowToken(), 0);
 }

代码示例来源:origin: stackoverflow.com

public static void hideKeyboard(Activity activity) {
  InputMethodManager imm = (InputMethodManager) activity.getSystemService(Activity.INPUT_METHOD_SERVICE);
  //Find the currently focused view, so we can grab the correct window token from it.
  View view = activity.getCurrentFocus();
  //If no view currently has focus, create a new one, just so we can grab a window token from it
  if (view == null) {
    view = new View(activity);
  }
  imm.hideSoftInputFromWindow(view.getWindowToken(), 0);
}

代码示例来源:origin: nickbutcher/plaid

public static void hideIme(@NonNull View view) {
  InputMethodManager imm = (InputMethodManager) view.getContext().getSystemService(Context
      .INPUT_METHOD_SERVICE);
  imm.hideSoftInputFromWindow(view.getWindowToken(), 0);
}

代码示例来源:origin: stackoverflow.com

private class MyFocusChangeListener implements OnFocusChangeListener {

  public void onFocusChange(View v, boolean hasFocus){

    if(v.getId() == R.id.textbox && !hasFocus) {

      InputMethodManager imm =  (InputMethodManager) getSystemService(Context.INPUT_METHOD_SERVICE);
      imm.hideSoftInputFromWindow(v.getWindowToken(), 0);

    }
  }
}

代码示例来源:origin: stackoverflow.com

public static void hideKeyboard(Context ctx) {
 InputMethodManager inputManager = (InputMethodManager) ctx
 .getSystemService(Context.INPUT_METHOD_SERVICE);
 // check if no view has focus:
  View v = ((Activity) ctx).getCurrentFocus();
  if (v == null)
   return;
 inputManager.hideSoftInputFromWindow(v.getWindowToken(), 0);
}

代码示例来源:origin: smuyyh/BookReader

/**
 * 隐藏键盘
 *
 * @param view
 * @return
 */
public static boolean hideSoftInput(View view) {
  InputMethodManager imm = (InputMethodManager) view.getContext().getSystemService(Context.INPUT_METHOD_SERVICE);
  return imm.hideSoftInputFromWindow(view.getWindowToken(), 0);
}

代码示例来源:origin: Jacksgong/JKeyboardPanelSwitch

public static void hideKeyboard(final View view) {
  InputMethodManager imm =
      (InputMethodManager) view.getContext()
          .getSystemService(Context.INPUT_METHOD_SERVICE);
  imm.hideSoftInputFromWindow(view.getWindowToken(), 0);
}

代码示例来源:origin: Naoki2015/CircleDemo

public static void hideSoftInput(Context context, View view){
  InputMethodManager imm = (InputMethodManager) context.getSystemService(Context.INPUT_METHOD_SERVICE);
  imm.hideSoftInputFromWindow(view.getWindowToken(), 0); //强制隐藏键盘
}

代码示例来源:origin: jMonkeyEngine/jmonkeyengine

public void run() {
    InputMethodManager manager =
        (InputMethodManager)view.getContext().getSystemService(Context.INPUT_METHOD_SERVICE);
    if (show) {
      manager.showSoftInput(view, 0);
    } else {
      manager.hideSoftInputFromWindow(view.getWindowToken(), 0);
    }
  }
});

代码示例来源:origin: jaydenxiao2016/AndroidFire

/**
 * 隐藏软键盘
 *
 * @param view
 */
public static void hideSoftKeyboard(View view) {
  Context context = view.getContext();
  InputMethodManager imm = (InputMethodManager) context
      .getSystemService(Context.INPUT_METHOD_SERVICE);
  imm.hideSoftInputFromWindow(view.getWindowToken(), 0);
}

代码示例来源:origin: stackoverflow.com

// Update the EditText so it won't popup Android's own keyboard, since I have my own.
 EditText editText = (EditText)findViewById(R.id.edit_mine);
 editText.setOnTouchListener(new OnTouchListener() {
   @Override
   public boolean onTouch(View v, MotionEvent event) {
     v.onTouchEvent(event);
     InputMethodManager imm = (InputMethodManager)v.getContext().getSystemService(Context.INPUT_METHOD_SERVICE);
     if (imm != null) {
       imm.hideSoftInputFromWindow(v.getWindowToken(), 0);
     }                
     return true;
   }
 });

代码示例来源:origin: JessYanCoding/MVPArms

/**
 * 隐藏软键盘
 *
 * @param context
 * @param view
 */
public static void hideSoftKeyboard(Context context, View view) {
  if (view == null)
    return;
  InputMethodManager inputMethodManager = (InputMethodManager) context.getSystemService(
      Context.INPUT_METHOD_SERVICE);
  if (inputMethodManager.isActive())
    inputMethodManager.hideSoftInputFromWindow(
        view.getWindowToken(), 0);
}

代码示例来源:origin: MindorksOpenSource/android-mvp-architecture

public static void hideSoftInput(Activity activity) {
  View view = activity.getCurrentFocus();
  if (view == null) view = new View(activity);
  InputMethodManager imm = (InputMethodManager) activity
      .getSystemService(Activity.INPUT_METHOD_SERVICE);
  imm.hideSoftInputFromWindow(view.getWindowToken(), 0);
}

代码示例来源:origin: seven332/EhViewer

public static void hideSoftInput(Activity activity) {
  View view = activity.getCurrentFocus();
  if (view != null) {
    InputMethodManager imm = (InputMethodManager) activity.getSystemService(Context.INPUT_METHOD_SERVICE);
    imm.hideSoftInputFromWindow(view.getWindowToken(), 0);
  }
}

代码示例来源:origin: arimorty/floatingsearchview

public static void closeSoftKeyboard(Activity activity) {
  View currentFocusView = activity.getCurrentFocus();
  if (currentFocusView != null) {
    InputMethodManager imm = (InputMethodManager) activity.getSystemService(Context.INPUT_METHOD_SERVICE);
    imm.hideSoftInputFromWindow(currentFocusView.getWindowToken(), 0);
  }
}

代码示例来源:origin: north2016/T-MVP

/**
   * 隐藏软键盘
   */
  public static void hideKeyboard(Activity c) {
    try {
      InputMethodManager imm = (InputMethodManager) c
          .getSystemService(Context.INPUT_METHOD_SERVICE);
      imm.hideSoftInputFromWindow(c.getCurrentFocus().getWindowToken(), 0);
    } catch (NullPointerException e) {
    }
  }
}

代码示例来源:origin: stackoverflow.com

FrameLayout touchInterceptor = (FrameLayout)findViewById(R.id.touchInterceptor);
touchInterceptor.setOnTouchListener(new OnTouchListener() {
  @Override
  public boolean onTouch(View v, MotionEvent event) {
    if (event.getAction() == MotionEvent.ACTION_DOWN) {
      if (mEditText.isFocused()) {
        Rect outRect = new Rect();
        mEditText.getGlobalVisibleRect(outRect);
        if (!outRect.contains((int)event.getRawX(), (int)event.getRawY())) {
          mEditText.clearFocus();
          InputMethodManager imm = (InputMethodManager) v.getContext().getSystemService(Context.INPUT_METHOD_SERVICE); 
          imm.hideSoftInputFromWindow(v.getWindowToken(), 0);
        }
      }
    }
    return false;
  }
});

代码示例来源:origin: mikepenz/MaterialDrawer

/**
   * Helper to hide the keyboard
   *
   * @param act
   */
  public static void hideKeyboard(Activity act) {
    if (act != null && act.getCurrentFocus() != null) {
      InputMethodManager inputMethodManager = (InputMethodManager) act.getSystemService(Activity.INPUT_METHOD_SERVICE);
      inputMethodManager.hideSoftInputFromWindow(act.getCurrentFocus().getWindowToken(), 0);
    }
  }
}

相关文章

微信公众号

最新文章

更多

View类方法