Tap outside edittext to lose focus

后端 未结 9 1576
萌比男神i
萌比男神i 2020-12-24 02:02

I just want when click outside the \"edittext\" to automatically lose focus and hide keyboard. At the moment, if I click on the \"edittext\" it focuses but i need to hit the

9条回答
  •  有刺的猬
    2020-12-24 02:36

    set in a button or any view: this.getCurrentFocus().clearFocus(); For example:

    @Override
    public boolean onMenuOpened(int featureId, Menu menu) {
        InputMethodManager imm = (InputMethodManager) getSystemService(INPUT_METHOD_SERVICE);
        imm.hideSoftInputFromWindow(getCurrentFocus().getWindowToken(), 0);
        this.getCurrentFocus().clearFocus();
        return super.onMenuOpened(featureId, menu);
    }
    

提交回复
热议问题