我在我的自定义对话框中有2个editfields,它是从ACtivity调用的,其中1个是“trxtPassword”和其他“text”类型。键盘不会出现在“文本”类型的编辑框中,而是出现在“textPassword”编辑文本中,然后不会执行。隐藏键盘密码字段Android
我尝试以下,但没有任何工程:
InputMethodManager inputManager = (InputMethodManager)mContext.getSystemService(Context.INPUT_METHOD_SERVICE);
inputManager.hideSoftInputFromWindow(this.getCurrentFocus().getWindowToken(), InputMethodManager.HIDE_NOT_ALWAYS);
//inputManager.hideSoftInputFromWindow(txt_username.getWindowToken(), 0);
//inputManager.hideSoftInputFromWindow(txt_password.getWindowToken(), 0);
如果我让txt_password.setInputType(0);那么其他人可以很容易地看到密码,这样就不能使用。
还有什么可以实现的目标?我没有套住onLostFocus上的txt
txt_password.setOnFocusChangeListener(new View.OnFocusChangeListener() {
@Override
public void onFocusChange(View v, boolean hasFocus) {
if (hasFocus == false) {
InputMethodManager inputManager = (InputMethodManager) mContext.getSystemService(Context.INPUT_METHOD_SERVICE);
inputManager.hideSoftInputFromWindow(LoginDialog.this.getCurrentFocus().getWindowToken(), InputMethodManager.HIDE_IMPLICIT_ONLY);
}
}
});
但不幸的是,一旦进入,如果我点击任何地方或任何复选框,然后还重点不是从txt_password场丢失。只有当我点击另一个editText然后onFocusChange事件被触发并抛出错误并且应用程序关闭时,才会丢失这些信息。
任何想法如何做到这一点?
只是为了澄清: 是您的目标是,让使键盘不会出现? 或者你是否试图在完成之后关闭键盘? – HaemEternal 2011-04-14 15:28:24
我试图反驳他的键盘,一旦我点击密码文本字段外的任何地方。 – Tvd 2011-04-14 15:52:42
用户在输入密码后,是否不适合单击键盘上的“完成”按钮以关闭键盘? (例如setImeOptions(EditorInfo.IME_ACTION_DONE);) – HaemEternal 2011-04-18 08:28:13