簡體   English   中英

Android:當鍵盤打開時,webview無法滾動

[英]Android: webview doesn't scroll enough when keyboard opens

在我的應用程序中,我有一個webview,它加載用戶應該執行身份驗證的網頁。 當用戶在網頁中選擇一些輸入字段時,webview應該:

  1. 專注於該領域
  2. 打開鍵盤
  3. 執行向上滾動以便用戶繼續看到該字段

但是,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.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM