1

How does EditText still have focus after the soft keyboard is hidden (user presses Done/Enter/Search button)?

Could you please provide me some explanation about this?

0

3 Answers 3

1

That's the default Android behaviour. You can call view.clearFocus() on Enter key press to override this.

0

Your app and Android soft keyboard (stock one) are different app processes. And while Android takes care of "notifying" the soft keyboard app on your app's EditText focus requests, neither Android nor the soft keyboard app should be responsible for your app's EditText focus changes. Your app has enough callbacks from the soft keyboard at its disposal to clear focus.

-1

- Add Following Line of Code in your Specific Activity.

EditText edt_user = findViewById(R.id.edt_user);      
    InputMethodManager imm = (InputMethodManager)this.getSystemService(Service.INPUT_METHOD_SERVICE);
        imm.showSoftInput(edt_user,0);

    edt_user.setOnKeyListener(new OnKeyListener() {

        @Override
        public boolean onKey(View v, int keyCode, KeyEvent event) {
            // TODO Auto-generated method stub
            if ((event.getAction() == KeyEvent.ACTION_DOWN)
                    && (keyCode == KeyEvent.KEYCODE_ENTER)) {

                edt_user.clearFocus();
            }
            return false;
        }
    });

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.