How to hide keyboard on enter key

时光怂恿深爱的人放手 提交于 2019-12-04 04:35:31
Uttam

I am not sure but you should try this code:-

youredittext.setOnEditorActionListener(new TextView.OnEditorActionListener() {

    @Override
    public boolean onEditorAction(TextView v, int keyCode, KeyEvent event) {
        if ((event.getAction() == KeyEvent.ACTION_DOWN) && (keyCode == KeyEvent.KEYCODE_ENTER)) {
            // hide virtual keyboard
            InputMethodManager imm = (InputMethodManager) getContext().getSystemService(Context.INPUT_METHOD_SERVICE);
            imm.hideSoftInputFromWindow(youredittext.getWindowToken(), 0);
            return true;
        }
        return false;
    }
});

I hope this will help..

The Best Way To Do This, Is To Add Following Codes In XML File

android:imeOptions="actionDone"

I am not understand why people suggestion java codes if they have better option

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!