Phonegap Android keyboard covers input elements scrolling is disabled

前端 未结 10 1559
夕颜
夕颜 2020-12-15 07:12

I\'ve tried many different solutions and nothing is quite what I want. What I want is for the keyboard to show on top of the content (keeping the content the same size) whi

10条回答
  •  误落风尘
    2020-12-15 07:28

    I added an event listener for the keyboard event and scrolled to the input only if it was off screen.

    For my case I only wanted to scroll when the keyboard was being shown for the first time, and only if the input item was offscreen.

    document.addEventListener('showkeyboard', onKeyboardShow, false);
    
    
     function onKeyboardShow(e) {        
        setTimeout(function() {
          e.target.activeElement.scrollIntoViewIfNeeded()
        }, 500) //needed timeout to wait for viewport to resize
      }
    

    To get the showkeyboard event to fire I needed to have the following in my AndroidManifest.xml

      android:windowSoftInputMode="adjustResize"
    

提交回复
热议问题