android.app.Activity.getCurrentFocus()方法的使用及代码示例

x33g5p2x  于2022-01-15 转载在 其他  
字(7.7k)|赞(0)|评价(0)|浏览(768)

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

Activity.getCurrentFocus介绍

暂无

代码示例

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

public static void hideSoftKeyboard(Activity activity) {
  InputMethodManager inputMethodManager = 
    (InputMethodManager) activity.getSystemService(
      Activity.INPUT_METHOD_SERVICE);
  inputMethodManager.hideSoftInputFromWindow(
    activity.getCurrentFocus().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: 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);
    }
  }
}

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

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

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

public static boolean showSoftInput(Activity activity) {
  View view = activity.getCurrentFocus();
  if (view != null) {
    InputMethodManager imm = (InputMethodManager) view.getContext().getSystemService(
        Context.INPUT_METHOD_SERVICE);
    return imm.showSoftInput(view, InputMethodManager.SHOW_FORCED);
  }
  return false;
}

代码示例来源: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: 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: 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: 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: Rukey7/MvpApp

/**
 * 关闭键盘事件.
 *
 * @param context the context
 */
public static void closeSoftInput(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);
  }
}

代码示例来源:origin: joyoyao/superCleanMaster

/**
 * 关闭键盘事件.
 *
 * @param context the context
 */
public static void closeSoftInput(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);
  }
}

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

/**
 * To show the panel(hide the keyboard automatically if the keyboard is showing) with
 * non-layout-conflict.
 *
 * @param panelLayout the layout of panel.
 * @see KPSwitchPanelLayoutHandler
 */
public static void showPanel(final View panelLayout) {
  final Activity activity = (Activity) panelLayout.getContext();
  panelLayout.setVisibility(View.VISIBLE);
  if (activity.getCurrentFocus() != null) {
    KeyboardUtil.hideKeyboard(activity.getCurrentFocus());
  }
}

代码示例来源:origin: cymcsg/UltimateAndroid

/**
 * Hide soft keyboard method.
 *
 * @param context
 * @param activity
 */
public static void hiddenKeyboard(Context context, Activity activity) {
  try {
    InputMethodManager imm = (InputMethodManager) context.getSystemService(Context.INPUT_METHOD_SERVICE);
    if (activity.getCurrentFocus() != null) {
      if (activity.getCurrentFocus().getWindowToken() != null) {
        imm.hideSoftInputFromWindow(activity
                .getCurrentFocus().getWindowToken(),
            InputMethodManager.HIDE_NOT_ALWAYS);
      }
    }
  } catch (Exception e) {
    e.printStackTrace();
  }
}

代码示例来源:origin: yanzhenjie/NoHttp

@Override
void closeInputMethod() {
  Activity activity = getSource();
  View focusView = activity.getCurrentFocus();
  if (focusView != null) {
    InputMethodManager manager =
     (InputMethodManager)activity.getSystemService(Context.INPUT_METHOD_SERVICE);
    if (manager != null) {
      manager.hideSoftInputFromWindow(focusView.getWindowToken(), 0);
    }
  }
}

代码示例来源:origin: k9mail/k-9

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

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

/**
 * Hide the panel and the keyboard.
 *
 * @param panelLayout the layout of panel.
 */
public static void hidePanelAndKeyboard(final View panelLayout) {
  final Activity activity = (Activity) panelLayout.getContext();
  final View focusView = activity.getCurrentFocus();
  if (focusView != null) {
    KeyboardUtil.hideKeyboard(activity.getCurrentFocus());
    focusView.clearFocus();
  }
  panelLayout.setVisibility(View.GONE);
}

代码示例来源:origin: pchmn/MaterialChipsInput

@Override
public boolean dispatchTouchEvent(MotionEvent motionEvent) {
  if (motionEvent.getAction() == MotionEvent.ACTION_DOWN) {
    View v = mActivity.getCurrentFocus();
    if(v instanceof DetailedChipView) {
      Rect outRect = new Rect();
      v.getGlobalVisibleRect(outRect);
      if (!outRect.contains((int) motionEvent.getRawX(), (int) motionEvent.getRawY())) {
        ((DetailedChipView) v).fadeOut();
      }
    }
    if (v instanceof ChipsInputEditText) {
      Rect outRect = new Rect();
      v.getGlobalVisibleRect(outRect);
      if (!outRect.contains((int) motionEvent.getRawX(), (int) motionEvent.getRawY())
          && !((ChipsInputEditText) v).isFilterableListVisible()) {
        InputMethodManager imm = (InputMethodManager) mActivity.getSystemService(Context.INPUT_METHOD_SERVICE);
        imm.hideSoftInputFromWindow(v.getWindowToken(), 0);
      }
    }
  }
  return mLocalCallback.dispatchTouchEvent(motionEvent);
}

代码示例来源:origin: RobotiumTech/robotium

return;
View focusedView = activity.getCurrentFocus();

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

public class Utils{
public static void hideKeyboard(@NonNull Activity activity) {
  // Check if no view has focus:
  View view = activity.getCurrentFocus();
  if (view != null) {
    InputMethodManager inputManager = (InputMethodManager) activity.getSystemService(Context.INPUT_METHOD_SERVICE);
    inputManager.hideSoftInputFromWindow(view.getWindowToken(), InputMethodManager.HIDE_NOT_ALWAYS);
  }
 }
}

代码示例来源:origin: weexteam/weex-hackernews

@Override
 public void run() {
  View currentFocus = ((Activity) context).getCurrentFocus();
  if (!(currentFocus instanceof EditText)) {
   mInputMethodManager.hideSoftInputFromWindow(getHostView().getWindowToken(), 0);
  }
 }
}, 16);

相关文章

Activity类方法