[英]hide virtual keyboard in android?
您好,即使用户触摸editText字段,我也不想显示虚拟键盘。
您是否尝试过将android:configChanges =“ keyboard | keyboardHidden”添加到您的活动中?
例如:
<activity android:name=".MyApp" android:label="@string/app_name" android:configChanges="keyboard|keyboardHidden">
不知道它是否适用于屏幕键盘以及物理键盘。
另外,您还可以使用InputMethodManager将屏幕键盘弄乱,例如,可以使用以下方法隐藏它:
InputMethodManager imm = (InputMethodManager)getSystemService(Context.INPUT_METHOD_SERVICE);
imm.hideSoftInputFromWindow(mCurretnView.getWindowToken(), 0);
在此问题中使用:
EditText edtView=(EditText)findViewById(R.id.editTextConvertValue);
edtView.setInputType(0);
InputMethodManager inputMethodManager = (InputMethodManager) currentActivity.getSystemService(Context.INPUT_METHOD_SERVICE);
if (isShow) {
if (currentActivity.getCurrentFocus() == null) {
inputMethodManager.toggleSoftInput(InputMethodManager.SHOW_FORCED, 0);
} else {
inputMethodManager.showSoftInput(currentActivity.getCurrentFocus(), InputMethodManager.SHOW_FORCED);
}
} else {
if (currentActivity.getCurrentFocus() == null) {
inputMethodManager.toggleSoftInput(InputMethodManager.HIDE_NOT_ALWAYS, 0);
} else {
inputMethodManager.hideSoftInputFromInputMethod(currentActivity.getCurrentFocus().getWindowToken(), InputMethodManager.HIDE_NOT_ALWAYS);
}
}
尝试这个
@Override
public boolean dispatchTouchEvent(MotionEvent event) {
boolean ret = super.dispatchTouchEvent(event);
InputMethodManager imm = (InputMethodManager)getSystemService(Context.INPUT_METHOD_SERVICE);
imm.hideSoftInputFromWindow(mCurretnView.getWindowToken(), 0);
return ret;
}
要么
editText.setOnTouchListener(new View.OnTouchListener() {
@Override
public boolean onTouch(View v, MotionEvent event) {
InputMethodManager imm = (InputMethodManager)getSystemService(Context.INPUT_METHOD_SERVICE);
imm.hideSoftInputFromWindow(mCurretnView.getWindowToken(), 0);
return false;
}
});
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.