【问题标题】:How to detect the keyboard on the android window - Titanium Appcelerator如何检测 android 窗口上的键盘 - Titanium Appcelerator
【发布时间】:2016-04-22 03:49:32
【问题描述】:

我需要一些东西来验证android应用程序窗口中键盘的存在......问题是我无法测试焦点/模糊输入,并且需要检查键盘......我看到了官方文档 Appcelerator 并且此功能仅适用于 iOS ...有人有解决方案吗?

iOS 的KeyboardVisible 属性:

http://docs.appcelerator.com/platform/latest/#!/api/Titanium.App-property-keyboardVisible

【问题讨论】:

    标签: android keyboard appcelerator appcelerator-titanium


    【解决方案1】:

    As you can see in the official docs 没有本地方法来检测键盘是否可见;如果您需要在用户打开窗口时显示键盘,请为“打开”和“恢复”添加一个侦听器(此侦听器来自活动,而不是窗口,并且当您的应用程序从后台转到foreground) 对于专注于您的领域的功能,如果您需要知道键盘何时打开以更改布局,android 已经尝试适合您(在这种情况下,将所有内容放在滚动视图中)。

    【讨论】:

      【解决方案2】:

      在 iOS 上,您可以收听 keyboardframechanged 事件。对于 Android,您或许可以使用these modules 之一。

      【讨论】:

        【解决方案3】:

        没有任何直接的方法可以做到这一点。但一些技巧可能会奏效。试试这个。

        final View activityRootView = findViewById(R.id.activityRoot);
        activityRootView.getViewTreeObserver().addOnGlobalLayoutListener(new OnGlobalLayoutListener() {
        @Override
        public void onGlobalLayout() {
            int heightDiff = activityRootView.getRootView().getHeight() - activityRootView.getHeight();
            if (heightDiff > 100) { // if more than 100 pixels, its probably a keyboard...
                ... do something here
            }
          }
        });
        

        【讨论】:

        • 感谢朋友的回复,但我正在使用 Appcelerator Titanium (js) 构建我的应用程序...不是原生的...
        猜你喜欢
        • 2011-09-08
        • 2015-03-03
        • 1970-01-01
        • 1970-01-01
        • 2016-06-25
        • 2012-02-02
        • 1970-01-01
        • 1970-01-01
        • 2011-04-06
        相关资源
        最近更新 更多