简体   繁体   English

SoftKeyboardStateListener在Lollipop设备上不起作用

[英]SoftKeyboardStateListener not working on Lollipop devices

This is the way I use to listen for soft keyboard visibility changing: 这是我用来监听软键盘可见性更改的方式:

    final SoftKeyboardStateWatcher softKeyboardStateWatcher
            = new SoftKeyboardStateWatcher(mainLayout);
    softKeyboardStateWatcher.addSoftKeyboardStateListener(new SoftKeyboardStateWatcher.SoftKeyboardStateListener() {
        @Override
        public void onSoftKeyboardOpened(int keyboardHeightInPx) {
            bottomToolbar.setVisibility(View.GONE);
        }

        @Override
        public void onSoftKeyboardClosed() {
            bottomToolbar.setVisibility(View.VISIBLE);
        }
    });

My app is made for SDK >= 16 and works perfect for all pre-Lollipop devices and I tested it on HTC One M7 with 5.0.2 Android and results were ok. 我的应用程序是为SDK> = 16开发的,适用于所有之前的Lollipop设备,我在HTC One M7和5.0.2 Android上进行了测试,结果还可以。 But, when I tried to test it with Nexus 4, API 22 and Nexus 5, API 23, onSoftKeyboardOpened and onSoftKeyboardClosed are never get called. 但是,当我尝试使用Nexus 4,API 22和Nexus 5,API 23 onSoftKeyboardOpened进行onSoftKeyboardClosed ,永远不会调用onSoftKeyboardOpenedonSoftKeyboardClosed

How can I solve this problem? 我怎么解决这个问题?

Thanks! 谢谢!

Try this, 尝试这个,

InputMethodManager imm = (InputMethodManager) getSystemService(Context.INPUT_METHOD_SERVICE);
imm.toggleSoftInput(InputMethodManager.SHOW_FORCED,0);

I hope this may help you.. :) 希望对您有帮助。.:)

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

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