input field hidden when soft keyboard appears in phonegap

后端 未结 8 956
失恋的感觉
失恋的感觉 2020-12-03 12:41

Creating a mobile application using Phonegap 3.6.3 for Android and iOS. The problem is only for Android, as iOS acts as I would like it to.

When I click on an input

相关标签:
8条回答
  • 2020-12-03 13:36

    I have the most efficient solution to scroll into input automatically and make it visible. First you need to add the keyboard plugin(cordova plugin add com.ionic.keyboard) as mentioned by @Fedir. Then on your event handler of 'keyboardshow' event add the following code:

    window.addEventListener('native.keyboardshow', function(e){ 
        setTimeout(function() {
            document.activeElement.scrollIntoViewIfNeeded();
        }, 100);
    });
    

    P.S: This is supported only on Android (Chrome) and Safari. :D

    0 讨论(0)
  • 2020-12-03 13:36

    Only one solution which worked for my full-screen app, it's to add to the Cordova application ionic-plugin-keyboard plugin

    cordova plugin add com.ionic.keyboard
    

    JS code :

    // This event fires when the keyboard will hide
    window.addEventListener('native.keyboardshow', keyboardShowHandler);
    
    function keyboardShowHandler(e){
        $("body").addClass("keyboardOn");
    }
    
    // This event fires when the keyboard will show
    window.addEventListener('native.keyboardhide', keyboardHideHandler);
    
    function keyboardHideHandler(e){
        $("body").removeClass("keyboardOn");
    }
    

    After that You could adjust the view with CSS.

    ref.: https://stackoverflow.com/a/25823491/634275

    0 讨论(0)
提交回复
热议问题