Android webview keyboard covering up input

Deadly 提交于 2019-12-04 05:01:57

问题


The desired effect for my android application is to have a webview with an input box and content. When the user clicks on the keyboard, the keyboard pushes the input box up, but does not resize the main content and just overlays ontop of it as seen in the diagram below.

The problem I'm experiencing is that the keyboard covers the input box and does not push it up.

This is currently a cordova android application. In the manifest, I have configued

 <activity android:configChanges="orientation|keyboardHidden|keyboard|screenSize|locale" android:label="@string/activity_name" android:launchMode="singleInstance" android:name="GigJam" android:theme="@android:style/Theme.DeviceDefault.NoActionBar" android:windowSoftInputMode="adjustPan">

Also in the config.xml:

   <preference name="Fullscreen" value="false" />

I used android:windowSoftInputMode="adjustPan" to prevent the screen from resizing which is what i want since I don't want the content to be squished. I've also tried configuring the css for the input box to be fixed and absolute (basically tied to the bottom of the webview.

From my understanding, when the keyboard pops up from an edit in the input box, that it would push up the box as well because the input box is constrained to the webview which will be pushed up as well.

Any advice appreciated, Thanks, D


回答1:


Android has a keyboard event that I listen to. When the show/hide is trigger, I grab the active input component and transform the box in the y axis by the size of the keyboard height which can be grab from the event in the listener. I transform back when the show is triggered.

Note: resize needs to be disabled for the android:windowSoftInputMode and set to "adjustPan"




回答2:


Use this line:

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


来源:https://stackoverflow.com/questions/39627268/android-webview-keyboard-covering-up-input

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