开发者

Hide Keyboard Password Field Android

I have 2 editfields in my Custom Dialog which is called from ACtivity, among them 1 is of "trxtPassword" and other of "text" type. Keyboard doesn't appear in "text" type editbox, but just comes on "textPassword" edittext, and then doesn't go only.

I tried the following, but nothing works:

    InputMethodManager inputManager = (InputMethodManager)mContext.getSystemService(Context.INPUT_METHOD_SERVICE);   
inputManager.hideSoftInputFromWindow(this.getCurrentFocus().ge开发者_JAVA技巧tWindowToken(), InputMethodManager.HIDE_NOT_ALWAYS); 

            //inputManager.hideSoftInputFromWindow(txt_username.getWindowToken(), 0);       
        //inputManager.hideSoftInputFromWindow(txt_password.getWindowToken(), 0);

If I make txt_password.setInputType(0); then others can see the password easily, so that can't be used.

What more can be doen to achieve the goal? I did to trap the onLostFocus on 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);
            }
        }
    });

But unfortunately, once entered, if I click anywhere else or any checkbox, then also the focus is not lost from the txt_password field. That is only lost if I click another editText and then the onFocusChange event is fired and throws error and the application shuts down.

Any idea how to accomplish this?


Use that to keep keyboard hidden on activity start

<activity
    android:name=".views.DrugstoreEditView"
    android:windowSoftInputMode="stateHidden"></activity>

And there is one usefull answer: How to hide soft keyboard on android after clicking outside EditText?

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜