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

后端 未结 3 516
小蘑菇
小蘑菇 2021-01-12 04:03

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 v

3条回答
  •  北恋
    北恋 (楼主)
    2021-01-12 04:32

    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.

提交回复
热议问题