Android+PhoneGap: android:windowSoftInputMode doesn't seem to work

浪尽此生 提交于 2019-12-19 05:54:35

问题


I'm developing a PhoneGap-based application and I googled much about how to make my webview adjust its height when virtual keyboard appears, or at least get height of the virtual keyboard. I found a lot of posts (including stackoverflow) which says that

android:windowSoftInputMode="adjustResize"

must be set in the manifest and I did that. I also found that for PhoneGap config.xml there's

<preference name="android-windowSoftInputMode" value="adjustResize"/>

setting and I pasted that too. I also tried combined value 'stateVisible|adjustResize' (not just 'adjustResize') for both parameters, but it seems to me that they both have NO EFFECT. I don't know, maybe I'm doing something wrong, but you can check the screenshots from the emulator (Android 4.0.3, but I also tried 4.1.2 and 4.2.2):
http://screencast.com/t/Mm0mw8c693 - keyboard visible
http://screencast.com/t/lZ2DomqeRR - keyboard hidden
On the screenshot I intentionally captured my manifest and config.xml settings, so you may see they're actually there.
I even recorded short video - http://screencast.com/t/xI9PMcMJxxx

As you may see, no any viewport resizing occur when keyboard shown / hidden. I also checked window.innerHeight using console.log() and it stays same for both visible and hidden keyboard.

Please, give me some advice.


回答1:


windowSoftInputMode="adjustResize" does not work if your app is in fullscreen mode (setting fullscreen to true in config.xml). It is Android's issue not Cordova. the issue CB-4404 was filed in Cordova bug tracker for months but recently it turns out that it is working as intended on Android bug tracker.

I solved the problem by setting fullscreen to false since it wasn't a problem for my app not to go fullscreen.




回答2:


I found I needed to to 3 things to resolve this issue, and prevent the actionBar from hiding itself, from scrolling out of view when the soft keyboard was brought up.

1) In AndroidManifest.xml, in the activity in question, I needed the line:

android:windowSoftInputMode="adjustResize"

The original problem is that adjustPan was present in the line above. At first, just the change above fixed the problem.

The project I am on uses fragments. In the onCreateView method, a different fragment had the line:

getActivity().getWindow().setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_ADJUST_PAN);

That line, unfortunately, overrode the adjustResize parameter in the Application manifest, and after that other fragment was displayed, the fragment that I fixed broke again. So, to fix the new break, I did 2 additional things.

2) I deleted the SOFT_INPUT_ADJUST_PAN line from the onCreateView method of that other fragment, because it did not need that line anyway.

3) In the onCreateView method of the fragment with which I am primarily concerned, I added the line:

getActivity().getWindow().setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_ADJUST_RESIZE);

Actually, doing either of items 2 or 3 would solve the problem. I did both to be thorough.




回答3:


either you can set this property in android.manifest explicitly to "adjustNothing" then you do not need to set "fullscreen" mode to false. but you have to update it every time you update/add android platform.



来源:https://stackoverflow.com/questions/19989890/androidphonegap-androidwindowsoftinputmode-doesnt-seem-to-work

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!