Input Text Field hidden below keyboard in Android webview

此生再无相见时 提交于 2020-01-14 12:41:26

问题


I implement Webview in my app in Fragment but in Webview EditText Field Hide when the keyboard appears.

I Set

WindowSoftInputMode = SoftInput.StateHidden | SoftInput.AdjustResize

and android:fitsSystemWindows="true"

but not working for me.

I also use custom RelativeLayout but it's not working.

Please help me to solve this issue.

My Code is below in Fragment

<ScrollView 
    xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    android:layout_height="match_parent"
    android:scrollbars="vertical"
    android:orientation="vertical"
    android:fillViewport="true">

  <RelativeLayout
        xmlns:android="http://schemas.android.com/apk/res/android"
        xmlns:app="http://schemas.android.com/apk/res-auto"
        android:orientation="vertical"
        android:layout_width="match_parent"
        android:layout_height="match_parent">

       some layout and label

       <RelativeLayout
                android:id="@+id/reletivePurchaseWebview"
                android:paddingLeft="20dp"
                android:paddingRight="20dp"
                android:visibility="gone"
                android:layout_height="match_parent"
                android:layout_width="match_parent">

                                    <android.webkit.WebView
                                        android:layout_width="match_parent"
                                        android:layout_height="match_parent"
                                        android:scrollbars="vertical"
                                        android:layout_above="@+id/lblBuyMore"
                                        android:id="@+id/webView" />

                                    <TextView
                                            android:layout_width="wrap_content"
                                            android:layout_height="wrap_content"
                                            android:padding="25dp"
                                            android:layout_centerHorizontal="true"
                                            android:id="@+id/lblBuyMore"
                                            android:layout_alignParentBottom="true"
                                            app:fontFamily="@font/lato_medium" 
                                            android:gravity="center_vertical"
                                            android:text="abc"
                                            android:textColor="#24E5BA"
                                            android:textSize="@dimen/textSize_11" />

        </RelativeLayout>
   </RelativeLayout>
</ScrollView >

回答1:


While I was trying to replicate your problem the first thing android studio complained was

I would suggest you to update your layout as following and try again.

<?xml version="1.0" encoding="utf-8"?>
<ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    android:layout_width="match_parent"                //  <-- Added this
    android:layout_height="match_parent"
    android:fillViewport="true"
    android:orientation="vertical"
    android:scrollbars="vertical">

<RelativeLayout 
        android:layout_width="match_parent"
        android:layout_height="wrap_content"       //     <-- Updated this
        android:orientation="vertical">

    //some layout and label

    <RelativeLayout
            android:id="@+id/reletivePurchaseWebview"
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:paddingLeft="20dp"
            android:paddingRight="20dp"
            android:visibility="gone">

        <android.webkit.WebView
                android:id="@+id/webView"
                android:layout_width="match_parent"
                android:layout_height="match_parent"
                android:layout_above="@+id/lblBuyMore"
                android:scrollbars="vertical" />

        <TextView
                android:id="@+id/lblBuyMore"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_alignParentBottom="true"
                android:layout_centerHorizontal="true"
                android:gravity="center_vertical"
                android:padding="25dp"
                android:text="abc"
                android:textColor="#24E5BA"
                android:textSize="@dimen/textSize_11"
                app:fontFamily="@font/lato_medium" />

    </RelativeLayout>
</RelativeLayout>

Manifest:

android:windowSoftInputMode="adjustPan" >


来源:https://stackoverflow.com/questions/58929968/input-text-field-hidden-below-keyboard-in-android-webview

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