直接上代码:

/** * 切换软键盘的状态 * 如当前为收起变为弹出,若当前为弹出变为收起 */private void toggleInput(Context context){        InputMethodManager inputMethodManager =        (InputMethodManager)context.getSystemService(Context.INPUT_METHOD_SERVICE);        inputMethodManager.toggleSoftInput(0, InputMethodManager.HIDE_NOT_ALWAYS);    }/** * 强制隐藏输入法键盘 */private void hideInput(Context context,View view){        InputMethodManager inputMethodManager =        (InputMethodManager)context.getSystemService(Context.INPUT_METHOD_SERVICE);        inputMethodManager.hideSoftInputFromWindow(view.getWindowToken(),0);    }/** * root为需要点击取消edittext焦点的layout */ root.setOnTouchListener(new View.OnTouchListener() {                        @Override                        public boolean onTouch(View v, MotionEvent event) {                            root.setFocusable(true);                            root.setFocusableInTouchMode(true);                            root.requestFocus();                            return true;                        }/** * 如果界面较为简单 */InputMethodManager inputMethodManager = (InputMethodManager)context.getSystemService(Context.INPUT_METHOD_SERVICE); @Override    public boolean onTouchEvent(MotionEvent event) {        // TODO Auto-generated method stub        if(event.getAction() == MotionEvent.ACTION_DOWN){            if(getCurrentFocus()!=null && getCurrentFocus().getWindowToken()!=null){                manager.hideSoftInputFromWindow(getCurrentFocus().getWindowToken(), InputMethodManager.HIDE_NOT_ALWAYS);            }        }        return super.onTouchEvent(event);    }

更多相关文章

  1. Android(安卓)AlertDialog 无法弹出输入法
  2. 通过设置android:imeOptions来改变软键盘Enter键图标
  3. Missing styles. Is the correct theme chosen for this layout?
  4. 在线音乐播放器
  5. android 摄像头(我想在类里面直接编辑UI界面,但是老是提示空指针,麻
  6. 界面有Edittext时有些手机进入界面会自动弹出键盘,消除自动弹出键
  7. 【Android(安卓)Socket专题】:UDP通信客户端app的demo的实现
  8. Android(安卓)Studio SDK 各版本下载方法
  9. android学习——处理 EditText 右下角为Done,回车 的情况

随机推荐

  1. google地图demo
  2. 如何把android设备中的固件dump出来
  3. Android(安卓)播放提示音
  4. 编程回忆之Android回忆(Android应用参数的
  5. Android中Data和String数据类型转换
  6. Android利用Looper在子线程中改变UI
  7. 录音及播放音频文件
  8. Android全屏对话框(附带延时关闭效果)
  9. Android(安卓)PendingIntent和Intent
  10. android获取系统当前年月日时分秒的时间