how to hide the virtual keyboard

不羁的心 提交于 2019-12-04 09:20:09

How about this?

EditText editText = (EditText) findViewById(R.id.edt_hello);

editText.setKeyListener(new NumberKeyListener() {

    @Override
    public int getInputType() {
        return InputType.TYPE_NULL;
    }

    @Override
    protected char[] getAcceptedChars() {
        return new char[] { '0', '1', '2', '3', '4', '5', '6', '7', '8', '9' };
    }
});

you have to use this in your AndroidManifest.xml file

So add

android:configChanges="orientation|keyboardHidden"

But with that your keyboard will always be hidden in that Activity.

Wouter

Dewr

I think you would like this post. Android App start with virtual keyboard open (android:windowSoftInputMode) though it is added in API Level 3.

Have you tried adding this in the Activity tag of your manifest? android:windowSoftInputMode="stateHidden"

Muhammad Usman Ghani

Add this in yourSendData() function

InputMethodManager imm = (InputMethodManager)getSystemService(Context.INPUT_METHOD_SERVICE);
    imm.hideSoftInputFromWindow(textEntered.getWindowToken(),0); 

OR use this

InputMethodManager.RESULT_UNCHANGED_SHOWN);
imm.toggleSoftInput(InputMethodManager.HIDE_IMPLICIT_ONLY, 0);

this work :)

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