|
【Android】
连接有物理键盘时,如何不要让弹出软键盘
发表于 2020-8-18 20:55:52
浏览:6201
|
回复:0
打印
只看该作者
[复制链接]
楼主
硬件:AIO-3399J,源码“Android 7.1 SDK源码(industry版本)”,下载时间2020-7-13。
- public class InputMethodService extends AbstractInputMethodService {
- public boolean onEvaluateInputViewShown() {
- if (mSettingsObserver == null) {
- Log.w(TAG, "onEvaluateInputViewShown: mSettingsObserver must not be null here.");
- return false;
- }
- if (mSettingsObserver.shouldShowImeWithHardKeyboard()) {
- return true;
- }
- Configuration config = getResources().getConfiguration();
- return config.keyboard == Configuration.KEYBOARD_NOKEYS
- || config.hardKeyboardHidden == Configuration.HARDKEYBOARDHIDDEN_YES;
- }
- }
复制代码
跟踪下来,连接有物理键盘时,config.keyboard的确是Configuration.KEYBOARD_QWERTY,但该函数要返回false,还须要同时满足两个条件,一是mSettingsObserver.shouldShowImeWithHardKeyboard()返回false,二是config.hardKeyboardHidden不是Configuration.HARDKEYBOARDHIDDEN_YES。我试下来,这两个条件都没有满足。
第一个条件:mSettingsObserver.shouldShowImeWithHardKeyboard()。会调用Settings.Secure.getInt(mService.getContentResolver(), Settings.Secure.SHOW_IME_WITH_HARD_KEYBOARD, 0),得到的值是ShowImeWithHardKeyboardType.TRUE,也就是说函数返回true。
第二个条件:config.hardKeyboardHidden值是Configuration.HARDKEYBOARDHIDDEN_YES。对这问题我对照之前下过的“Android 7.1 SDK源码”(非industry版本),发现两个版本在computeScreenConfigurationLocked时赋给config.hardKeyboardHidden值不一样。以下是industry版本,设的值是Configuration.HARDKEYBOARDHIDDEN_YES。
- void computeScreenConfigurationLocked(Configuration config) {
- ....
- // Let the policy update hidden states.
- config.keyboardHidden = Configuration.KEYBOARDHIDDEN_NO;
- config.hardKeyboardHidden = Configuration.HARDKEYBOARDHIDDEN_YES;
- config.navigationHidden = Configuration.NAVIGATIONHIDDEN_NO;
- mPolicy.adjustConfigurationLw(config, keyboardPresence, navigationPresence);
- }
复制代码
而在非industry版本,设置的值是Configuration.HARDKEYBOARDHIDDEN_NO。
——“Android 7.1 SDK源码(industry版本)”下,连接有物理键盘时,如何不要让弹出软键盘? |
|