Android softkeyboard issue with input in focus
I have an issue with the android softkeyboard overlapping the input fields when in focus. I have tried various solutions but to no avail. My application is built using phonegap I have tried to change the android:windowSoftInputMode to various solutions but everything doesn't work. these are the issues i ahve
1) The login screen input field does not focus into the center of the screen when in focus unless it is typed into. This is when the android:windowSoftInputMode="adjustPan".
2) If android:windowSoftInputMode="adjustResize" the input field does come into the center of the screen but only when typed into and this also breaks the layout of a bottom nav bar which is pushed up by the keyboard.
Does anyone have any advice on what I should do??
I had the same problem. Here is a workaround:
Install com.ionic.keyboard plugin
Set this in your config.xml
<preference name="fullscreen" value="true" />
Add this to the bottom of your page
<div id="kbs" class="keyboardspace"></div>
Give the surrounding element the id "frame"
Add this to your css
.keyboardspace {
width: 100%;
height: 0;
}
Now register these two event listeners (I'm using jquery here, but it should also be possible without)
var window = angular.element($window);
window.on('native.keyboardshow', function (e) {
$("#kbs").height(e.keyboardHeight);
var focus = $(document.activeElement);
var pos = focus.offset();
var bottom = pos.top + focus.height() + 10;
var maxpos = $($window).height() - e.keyboardHeight;
if (bottom > maxpos) {
$("#frame").scrollTop(bottom - maxpos);
}
});
window.on('native.keyboardhide', function () {
console.log("native.keyboardhide");
$("#kbs").height(0);
});
Note that the frame has to be scrollable for this to work.
您在Softkeyboard.java中使用此代码:
@override
public void onComputeInsets(Insets outInsets){
super.onComputeInsets(outInsets);
if(!isFullscreenMode()){
outInsets.contentTopInsets = outInsets.visibleTopInsets;
}
}
链接地址: http://www.djcxy.com/p/24238.html
上一篇: 在Android中的对话框中显示ListView EditText中的焦点问题
下一篇: 输入焦点的Android软键盘问题