简体   繁体   English

Android:如何在屏幕上隐藏软键盘?

[英]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. 视图是getCurrentFocus(),getWindow()。getDecorView和我的布局上的某些视图-没有任何效果,因为键盘是由另一个应用程序调用的。

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? 那么,如何隐藏全局键盘?

Try this way, android:windowSoftInputMode="stateAlwaysHidden" For details information you may visit this link: 尝试这种方式, android:windowSoftInputMode="stateAlwaysHidden"有关详细信息,您可以访问以下链接:
https://developer.android.com/guide/topics/manifest/activity-element.html#wsoft https://developer.android.com/guide/topics/manifest/activity-element.html#wsoft

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM