javascript Phonegap:在 Android 键盘显示上调整 webview 的大小

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/21783730/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-10-27 21:40:55  来源:igfitidea点击:

Phonegap: Resize webview on keyboard display in Android

javascriptjquerycsscordovakeyboard

提问by Adam

I have a modal similar (with fixed positioning)to what facebook has for the comments in feed/chat in messenger in the latest android release. What I want looks similar to this:

我有一个类似于facebook 在最新 android 版本中的 feed/chat in messenger 中的评论的模态(具有固定定位)。我想要的看起来类似于:

enter image description here

在此处输入图片说明

So when you focus on the input the keyboard opens and shrinks the webview. It's not working by default and I can't find any solution.

因此,当您专注于输入时,键盘会打开并缩小 web 视图。默认情况下它不起作用,我找不到任何解决方案。

I tried to add this preference to config.xmlbut adjustResizeis not doing anything and stateVisiblejust opens the keyboard when I start the app.

我尝试将此首选项添加到config.xmladjustResize没有做任何事情,stateVisible只是在启动应用程序时打开键盘。

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

Which is weird. As of the Android DocumentationadjustResize should do this:

这很奇怪。在Android 文档中adjustResize 应该这样做:

The activity's main window is always resized to 
make room for the soft keyboard on screen.

I'm using Phonegap 3.0 and I have a Nexus 5 with kitkat for testing.

我正在使用 Phonegap 3.0 并且我有一台带有 kitkat 的 Nexus 5 用于测试。

回答by QuickFix

On my project created with phonegap 3.0, by default the app was full screen activity and the keyboard hid the app and the app was not resized.

在我使用 phonegap 3.0 创建的项目中,默认情况下,应用程序是全屏活动,键盘隐藏了应用程序,并且未调整应用程序的大小。

I edited config.xml and set <preference name="fullscreen" value="false" />, then the app was no more be full screen and when the soft keyboard was opened, the app was resized to fit the rest of the screen.

我编辑了 config.xml 和 set <preference name="fullscreen" value="false" />,然后应用程序不再是全屏,当软键盘打开时,应用程序被调整大小以适应屏幕的其余部分。

回答by Rupesh

I found the solution.. for specially "sencha/phonegap/cordova" users.

我找到了解决方案..专门针对“sencha/phonegap/cordova”用户。

Edit the Main activity in android manifest file add this attribute.

编辑android 清单文件中Main 活动添加此属性。

android:windowSoftInputMode="adjustNothing"

android:windowSoftInputMode="adjustNothing"

 <activity android:configChanges="orientation|keyboardHidden|keyboard|screenSize|locale" android:windowSoftInputMode="adjustNothing"  android:label="@string/app_name" android:launchMode="singleTop" android:name="com.company.appName.MainActivity" android:screenOrientation="portrait" android:theme="@android:style/Theme.Black.NoTitleBar">
<intent-filter>
    <action android:name="android.intent.action.MAIN" />
    <category android:name="android.intent.category.LAUNCHER" />
</intent-filter> 
</activity>