当前位置: 代码迷 >> Web前端 >> 手动抚摸――软键盘自动退出
  详细解决方案

手动抚摸――软键盘自动退出

热度:128   发布时间:2012-10-12 10:17:04.0
手动触摸――软键盘自动退出

如果想点击哪个地方,然后让软键盘自动消失,就设置它

// 点击Activity中的任意位置,edittext焦距消失,软键盘隐藏
	public void CloseKeyBoard() {
		direct_times_cast.clearFocus();
		InputMethodManager imm = (InputMethodManager) getSystemService(Context.INPUT_METHOD_SERVICE);
		imm.hideSoftInputFromWindow(direct_times_cast.getWindowToken(), 0);

		direct_chase_number.clearFocus();
		imm = (InputMethodManager) getSystemService(Context.INPUT_METHOD_SERVICE);
		imm.hideSoftInputFromWindow(direct_chase_number.getWindowToken(), 0);
	}

	public boolean onTouchEvent(MotionEvent event) {
		CloseKeyBoard();
		return super.onTouchEvent(event);
	}

?

private EditText direct_times_cast, direct_chase_number;

	direct_times_cast = (EditText) findViewById(R.id.direct_times_cast);
		direct_chase_number = (EditText) findViewById(R.id.direct_chase_number);

?

  相关解决方案