Code example for InputMethodManager

Methods: showSoftInput, toggleSoftInput

0
  public static void openInputMethod(Activity ac) {
    View v = ac.getWindow().peekDecorView();
    if (v != null && v.getWindowToken() != null) {
      InputMethodManager imm = (InputMethodManager) ac.getSystemService(ac.INPUT_METHOD_SERVICE);
      // 如果输入法打开则关闭,如果没打开则打开 
      imm.toggleSoftInput(0, InputMethodManager.HIDE_NOT_ALWAYS);
      imm.showSoftInput(v, InputMethodManager.SHOW_FORCED);
    } 
  } 
 
  /** 
   * 缩放图片大小 
   */ 
  public static Bitmap changeBitmapSize(Bitmap bitmap, int newWidth, int newHeight) {
    int width = bitmap.getWidth();
    int height = bitmap.getHeight();
    // 计算缩放比例 
    float scaleWidth = ((float) newWidth) / width;
    float scaleHeight = ((float) newHeight) / height;
    // 取得想要缩放的matrix参数 
    Matrix matrix = new Matrix();