UPDATE
Following my initial answer, the JavaScript below will work on windowSoftInputMode="adjustResize" , however it will not work on "adjustPan" because the JavaScript resize() event will not be fired when the keyboard is shown.
However, as mentioned here , you can capture the event displayed on the keyboard on the Java side by connecting the GlobalLayoutListener to ViewTreeObserver :
package com.com.app; import org.apache.cordova.Config; import org.apache.cordova.DroidGap; import android.os.Bundle; import android.view.WindowManager; public class BDH extends DroidGap { @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState);
So, when the keyboard is displayed, you can run the JavaScript function by indicating that the keyboard is displayed, then you can customize the screen:
var fieldFocused = null; function onKeyboardShowing() { if(fieldFocused != null) { $('body').scrollTo(fieldFocused, 500, {offset:-50}); } } $(document).on('focus', 'input, textarea', function() { fieldFocused = $(this); }); $(document).on('blur', 'input, textarea', function() { fieldFocused = null; });
ORIGINAL RESPONSE
We had a terrible time trying to fix a soft Android keyboard covering input fields. The solution I came up with is by no means "nice," but it worked ...
You will need jQuery, as well as another jQuery plugin called jQuery.ScrollTo by Ariel Flesher, found here .
Now add this to your JavaScript:
var fieldFocused = null; $(window).resize(function(e) { if(fieldFocused != null) { $('body').scrollTo(fieldFocused, 500, {offset:-50}); } }); $(document).on('focus', 'input, textarea', function() { fieldFocused = $(this); }); $(document).on('blur', 'input, textarea', function() { fieldFocused = null; });
When the textarea / input object is brought into focus, the DOM element is assigned to the variable. When the window changes, the window scrolls to bring the DOM element to the beginning.
We used android: windowSoftInputMode = "adjustResize" in the Android manifest.
As I said, these are not the most elegant fixes, but we implemented it in our PhoneGap application and it works.