Android: How to hide soft keyboard on screen off?

I'm developing a screenlock app. It starts fullscreen activity when screen turns off. And there's a problem: if user was using a soft keyboard when screen was turned off, the keyboard does not goes off the screen. And it looks like fullscreen activity and keyboard above it. So user can't unlock the device because back and home buttons are disabled and keyboard hides the unlock area.

I've tried to use:

InputMethodManager imm = (InputMethodManager)getSystemService(Context.INPUT_METHOD_SERVICE);
imm.hideSoftInputFromWindow(view.getWindowToken(), InputMethodManager.HIDE_NOT_ALWAYS);

where view is getCurrentFocus(), getWindow().getDecorView and some view on my layout - there is no any effect because the keyboard was called by another app.

Also, part of my manifest:

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

it doesn't work too. So, how can I hide the keyboard globaly?

Upvotes: 0

Views: 1061

Answers (1)

IntelliJ Amiya
IntelliJ Amiya

Reputation: 75788

Try this way,android:windowSoftInputMode="stateAlwaysHidden" For details information you may visit this link:
https://developer.android.com/guide/topics/manifest/activity-element.html#wsoft

Upvotes: 1

Related Questions