Android弹出关闭输入法

 注意 : editText.requestFocus();    在需要弹出输入法的时候

  http://blog.csdn.net/zgf1991/article/details/17097849


[java]  view plain copy 在CODE上查看代码片 派生到我的代码片
  1. public class InputMethodUtil {  
  2.     public static Context mContext;  
  3.     public static Handler inputHandler = new Handler() {  
  4.         public void handleMessage(android.os.Message msg) {  
  5.             View view = (View) msg.obj;  
  6.             showInput(mContext, view);  
  7.         };  
  8.     };  
  9.   
  10.     /** 
  11.      *  
  12.      * @param context 
  13.      * @param view 
  14.      * @param delayMillis 
  15.      *            : onCreate()  中不能马上弹出,需要稍微延时 
  16.      */  
  17.     public static void showInputMethod(Context context, View view,  
  18.             long delayMillis) {  
  19.         mContext = context;  
  20.         Message msg = inputHandler.obtainMessage();  
  21.         msg.obj = view;  
  22.         inputHandler.sendMessageDelayed(msg, delayMillis);  
  23.     }  
  24.   
  25.     private static void showInput(Context context, View view) {  
  26.         InputMethodManager im = (InputMethodManager) context  
  27.                 .getSystemService(Context.INPUT_METHOD_SERVICE);  
  28.         im.showSoftInput(view, 0);  
  29.   
  30.     }  
  31.   
  32.     /** 
  33.      *  
  34.      * @param context 
  35.      *            关闭输入法,需要一个activity 
  36.      */  
  37.     public static void closeInputMethod(Activity context) {  
  38.         try {  
  39.             InputMethodManager inputMethodManager = (InputMethodManager) context  
  40.                     .getSystemService(Context.INPUT_METHOD_SERVICE);  
  41.             inputMethodManager.hideSoftInputFromWindow(context  
  42.                     .getCurrentFocus().getWindowToken(),  
  43.                     InputMethodManager.HIDE_NOT_ALWAYS);  
  44.   
  45.         } catch (Exception e) {  
  46.             // TODO: handle exception  
  47.             Log.d("""关闭输入法异常");  
  48.         }  
  49.     }  
  50. }  
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值