android 软键盘的弹出问题总结

项目中用到软键盘的管理总结如下:

在开始进入页面时不弹出键盘

方法一:在包含EditText外层布局上添加

android:focusable="true"
android:focusableInTouchMode="true"

抢在EditText获取焦点,即可

方法二:在onResume中加入这行代码

getWindow().setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_ADJUST_RESIZE |
                WindowManager.LayoutParams.SOFT_INPUT_STATE_HIDDEN);


1,绑定软键盘到EditText:

edit.setFocusable(true);
			edit.setFocusableInTouchMode(true);
			edit.requestFocus();
			InputMethodManager inputManager = (InputMethodManager)edit.getContext().getSystemService(Context.INPUT_METHOD_SERVICE);
	        inputManager.showSoftInput(edit, 0);


2,去除软键盘显示:

editMsgView.setText("");
					editMsgView.clearFocus();
					//close InputMethodManager
					InputMethodManager imm = (InputMethodManager)getSystemService(Context.INPUT_METHOD_SERVICE); 
					imm.hideSoftInputFromWindow(editMsgView.getWindowToken(), 0);
EditText始终不弹出软件键盘

EditText edit=(EditText)findViewById(R.id.edit); edit.setInputType(InputType.TYPE_NULL);

还可以

InputMethodManager imm = (InputMethodManager)v.getContext().getSystemService(Context.INPUT_METHOD_SERVICE);   

  if(imm.isActive()){   //这里可以判断也可以不判断

    imm.hideSoftInputFromWindow(v.getApplicationWindowToken(), 0 );   

  }   



1,在设置软键盘弹出属性界面加载后,软键盘不能弹出,不能弹出软键盘的主要原因是Android程序未将屏幕绘制完成,所以延迟一定时间,弹出软键盘。

方法一:

private Handler hander=new Handler(){
		public void handleMessage(android.os.Message msg) {
			edit.setFocusable(true);
			edit.setFocusableInTouchMode(true);
			edit.requestFocus();
			InputMethodManager inputManager = (InputMethodManager)edit.getContext().getSystemService(Context.INPUT_METHOD_SERVICE);
	        inputManager.showSoftInput(edit, 0);
		};
	};

@Override
		public void onWindowFocusChanged(boolean hasWindowFocus) {
			if(visible){	
				hander.sendEmptyMessageDelayed(0, 1000);
			}
		}

方法二:

Timer timer = new Timer();
timer.schedule(new TimerTask() {
	@Override
	public void run() {
		InputMethodManager m = (InputMethodManager) editText.getContext().getSystemService(Context.INPUT_METHOD_SERVICE);
		m.toggleSoftInput(0, InputMethodManager.HIDE_NOT_ALWAYS);
	}
}, 300);

<activity android:windowSoftInputMode="stateVisible|adjustResize" . . . >
 该Activity主窗口总是被调整屏幕的大小以便留出软键盘的空间



你可能感兴趣的:(android 软键盘的弹出问题总结)