27
2017
09

工具类-软键盘

public class SoftKeyboardUtils {
     public static void closeBoard(Context context ) {
       InputMethodManager imm = (InputMethodManager) context
               .getSystemService( Context. INPUT_METHOD_SERVICE);
         imm.toggleSoftInput(InputMethodManager. SHOW_IMPLICIT ,
               InputMethodManager. HIDE_NOT_ALWAYS );
    }

     public static void hideSystemKeyBoard(Context context, View view ) {
       InputMethodManager imm = (InputMethodManager) context
               .getSystemService( Context. INPUT_METHOD_SERVICE);

         imm.hideSoftInputFromWindow( view.getWindowToken(),InputMethodManager. HIDE_NOT_ALWAYS );
    }

     public static void hideSystemKeyBoard(Context context, IBinder iBinder ) {
       InputMethodManager imm = (InputMethodManager) context
               .getSystemService( Context. INPUT_METHOD_SERVICE);

         imm.hideSoftInputFromWindow( iBinder,InputMethodManager. HIDE_NOT_ALWAYS );
    }

     public static void showKeyboard(Context context , View v ) {
        v.requestFocus();
       InputMethodManager imm = (InputMethodManager) context
               .getSystemService( Context. INPUT_METHOD_SERVICE);
        imm.showSoftInput( v, InputMethodManager.SHOW_FORCED );

    }

     public static void toggleKeyboard(Context context) {
       InputMethodManager imm = (InputMethodManager) context
               .getSystemService( Context. INPUT_METHOD_SERVICE);
        // 显示或者隐藏输入法
         imm.toggleSoftInput(InputMethodManager. SHOW_IMPLICIT , InputMethodManager.HIDE_NOT_ALWAYS );

    }
}
上一篇:Android 经常用到的开源框架 下一篇:工具类-万能Adapter