【问题标题】:Soft keyboard not pushing webview content up neither resizing软键盘不向上推 webview 内容也不调整大小
【发布时间】:2019-07-29 16:50:45
【问题描述】:

简单地说,在网页视图中加载内容并点击文本字段后,我的应用拒绝调整大小或平移。

这是我的设置

我有一个包含多个片段的 Activity。这是片段容器的布局。

 <android.support.v4.widget.DrawerLayout 
    xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"      
    android:id="@+id/drawer_layout"
    android:layout_width="match_parent" 
    android:layout_height="match_parent">
    <!-- MAIN CONTENT -->
    <FrameLayout 
       android:id="@+id/container"
       android:layout_width="match_parent"
       android:layout_height="match_parent"   
       android:background="@android:color/white" />

    <RelativeLayout
       android:layout_width="240dp"
       android:layout_height="match_parent"
       android:layout_gravity="start">

       <!-- ... -->
    </RelativeLayout>
</android.support.v4.widget.DrawerLayout>

这是 webview 片段的布局。

<RelativeLayout   
    xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent">

    <include
        android:id="@+id/tbOnlinePayment"
        layout="@layout/toolbar" />

    <WebView
        android:layout_below="@+id/tbOnlinePayment"
        android:id="@+id/paymentWebView"
        android:layout_width="match_parent"
        android:layout_height="match_parent"/>

    <ProgressBar
        android:id="@android:id/progress"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_centerInParent="true"/>

</RelativeLayout>

我的应用主题扩展 Theme.AppCompat.Light.DarkActionBar

我的尝试

  • 就像网上写的一样,我尝试了android:windowSoftInputMode="adjustResize"android:windowSoftInputMode="adjustPan"
  • 我知道在全屏模式下android:windowSoftInputMode="adjustResize" 不起作用,但我不会手动强制。我将应用的主题放在这里,因为也许有人知道这个主题以某种方式强制全屏显示。
  • 基于上述假设,我在应用的主题中添加了&lt;item name="android:windowFullscreen"&gt;false&lt;/item&gt;,但仍然没有结果。
  • webview 包装在scrollview 中。
  • webview 的高度更改为wrap_content
  • 基本上浏览了大部分 SO 帖子和解决方案。

我想要什么

我真的不在乎 webview 是否被调整大小或向上推。我想要的是键盘不隐藏输入字段。

【问题讨论】:

  • 在 Android Manifest 文件中尝试“android:windowSoftInputMode="adjustResize”,并在您的 html DOM 中使用元标记“height=device-height”。
  • 也可以试试 android:windowSoftInputMode="adjustNothing"
  • 我也有 android:theme="@android:style/Theme.NoTitleBar.Fullscreen" 阻止 adjustResize 工作。仅使用android:theme="@android:style/Theme.NoTitleBar" 使adjustResize 工作。最终与这个答案一起工作:stackoverflow.com/a/14565884/221458

标签: android


【解决方案1】:

我试过了:

    <activity
        android:name="com.myapp.MainActivity"
        android:configChanges="keyboard|keyboardHidden|orientation|screenSize"
        android:windowSoftInputMode="adjustResize">

adjustResize 解决了这个问题。

【讨论】:

    猜你喜欢
    • 2018-09-25
    • 1970-01-01
    • 2011-10-09
    • 2012-07-28
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多