View redrawn in the wrong position after closing the keyboard - Cordova/PhoneGap - Android
I have found a fix/hack, not a great one however it's better than nothing.
By hiding the html
tag and then re-displaying it redraws the view correctly.
fixAndroidKitkatDisplayBug: function () { $(document).on('blur', 'input', function () { var htmlTags = document.getElementsByTagName('html'); var html = htmlTags[0]; html.style.display = 'none'; html.offsetHeight; // no need to store this anywhere, the reference is enough html.style.display = 'block'; }); }
Then in the index.js, after the "onDeviceReady" I call this method like so
setTimeout(function (){ if (typeof(device) != 'undefined' && device.platform && device.platform == "Android" && device.version && parseFloat(device.version) == 4.4) { fixAndroidKitkatDisplayBug(); }}, 100);
(For me I needed the setTimeout in order for device to be defined)
I was able to fix the problem on our app by adding the following 'hack' to my submit button code.
$('html, body').scrollTop(0);$('#usernamefield').blur();$('#passwordfield').blur();$('#loginform_submit').blur();
So I forced the html and body elements to scroll to the very top and also made sure no element had focus so the softkeyboard would actually disappear before moving on.
Hope this helps you as well.
/Mika