Android webview中键盘遮挡了输入文本框

4

我在Fragment中实现了Webview,但是当键盘弹出时,Webview中的EditText字段会被隐藏。

我设置了

WindowSoftInputMode = SoftInput.StateHidden | SoftInput.AdjustResize

并且 android:fitsSystemWindows="true"

但对我无效。

我也使用自定义的 RelativeLayout,但它不起作用。

请帮助我解决这个问题。

我的代码在 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 >

展示你的布局。 - Rasel
请更新您的问题并附上您的布局代码。 - Networks
好的,现在检查 @网络。 - Adil Saiyad
你可以更新你的Java和XML代码吗? - Rahul Goswami
有人可以帮我吗? - Adil Saiyad
显示剩余2条评论
1个回答

2

当我尝试复制您的问题时,Android Studio 首先报错:

enter image description here

建议您按照以下方式更新您的布局并再次尝试:

<?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>

清单:

android:windowSoftInputMode="adjustPan" >

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接