首页 > 解决方案 > Cordova android - 键盘覆盖输入字段

问题描述

我知道这已被问过很多次,但没有一个回答提供解决方案。

<preference name="fullscreen" value="false" />这不是一个真正的修复,因为我希望应用程序是全屏的。

配置文件选项似乎没有做任何事情。我努力了:

android:windowSoftInputMode="adjustPan"
android:windowSoftInputMode="adjustResize"
android:windowSoftInputMode="adjustResize|stateHidden"

滚动偏移也不起作用,因为没有滚动空间。

$('.myinput').focus(function(e) {
    var container = $('.container'),
    scrollTo = $('.myinput');

    setTimeout((function() {
        container.animate({
            scrollTop: scrollTo.offset().top - container.offset().top + container.scrollTop()
        });
    }), 500);
});

截屏

标签: javascriptandroidhtmlcordova

解决方案


请安装:

cordova plugin add ionic-plugin-keyboard --save

然后让cordova准备在你的www文件夹中加载这个新插件。

document.addEventListener('deviceready', function(e){
    window.addEventListener('native.keyboardshow', function () {
            cordova.plugins.Keyboard.disableScroll(true);
        });
});

或者你可以试试这个javascript函数

<script>
      setInterval(function(){
      if( document.body.className.match('keyboard-open') ) {
      document.getElementById("messagearea").style.marginBottom="100px";
      }
                  else{
                     document.getElementById("messagearea").style.marginBottom="0px";
                  }

                  }, 1000);

  </script>

推荐阅读