[英]Android: webview doesn't scroll enough when keyboard opens
在我的应用程序中,我有一个webview,它加载用户应该执行身份验证的网页。 当用户在网页中选择一些输入字段时,webview应该:
但是,webview不会自动向上滚动,因此用户不再看到该字段。 如果用户尝试手动滚动,则webview只会进行一次小滚动 - 不足以让用户看到他需要的所有内容。 没有网页本身的问题,因为当我使用android chrome浏览到这个网页时,它会向上滚动以保持视野中的字段并允许滚动直到页面底部。 我已经阅读了以下问题: 当键盘打开时,WebView不会滚动 , adjustPan不会阻止键盘覆盖EditText,但答案并没有解决问题。
我当前的activity_web_viewlogin.xml:
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:id="@+id/portalWebViewWrapper"
android:orientation="vertical"
tools:context="com.hpe.sb.mobile.app.features.login.activities.WebViewLoginActivity">
<include
android:id="@+id/app_bar"
layout="@layout/app_bar" />
<ScrollView android:layout_width="match_parent"
android:layout_height="match_parent"
android:fillViewport="true">
<WebView
android:id="@+id/portalWebView"
android:layout_below="@id/app_bar"
android:layout_width="match_parent"
android:layout_margin="@dimen/activity_vertical_margin"
android:layout_height="match_parent"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true" />
</ScrollView>
</LinearLayout>
还试图ScrollView包含LinearLayout。
在我的AndroidManifest.xml中:
<activity
android:name=".features.login.activities.WebViewLoginActivity"
android:windowSoftInputMode="adjustResize"
android:label="" />
尝试调整adjust而不是adjustResize。
提前致谢!
感谢朋友,我现在有了解决方案。
在AndroidManifest.xml中:
<activity
android:name=".features.login.activities.WebViewLoginActivity"
android:label=""
android:windowSoftInputMode="adjustResize"
android:theme="@style/webview"/>
在styles.xml中:
<style name="webview" parent="AppTheme.NoActionBar">
<item name="windowNoTitle">true</item>
<item name="windowActionBar">false</item>
<item name="android:windowNoTitle">true</item>
<item name="android:windowActionBar">false</item>
<item name="android:windowFullscreen">false</item>
</style>
这是activity_web_viewlogin.xml:
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:id="@+id/portalWebViewWrapper"
tools:context="com.hpe.sb.mobile.app.features.login.activities.WebViewLoginActivity">
<include
android:id="@+id/app_bar"
layout="@layout/app_bar" />
<WebView
android:id="@+id/portalWebView"
android:layout_below="@id/app_bar"
android:layout_width="match_parent"
android:layout_margin="@dimen/activity_vertical_margin"
android:layout_height="match_parent"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true" />
</RelativeLayout>
活动布局没什么特别之处。 没有像@ramji解释的ScrollView它确实有效。 我相信它也适用于LinearLayout而不是RelativeLayout,对我来说无关紧要。
Webview已经附带可滚动,无需在scrollview内部使用替换您的代码:
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:id="@+id/portalWebViewWrapper"
android:orientation="vertical"
tools:context="com.hpe.sb.mobile.app.features.login.activities.WebViewLoginActivity">
<include
android:id="@+id/app_bar"
layout="@layout/app_bar" />
<WebView
android:id="@+id/portalWebView"
android:layout_below="@id/app_bar"
android:layout_width="match_parent"
android:layout_margin="@dimen/activity_vertical_margin"
android:layout_height="match_parent"/>
</LinearLayout>
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.