简体   繁体   English

键盘打开webview时不滚动

[英]When keyboard open webview not scrolling

I have a application 50% native 50% is webview. 我有一个应用程序50%原生50%是webview。 I have only 1 input in webview but this is the problem, when keyboard open not scrolling webview. 我在webview中只有1个输入,但这是问题,当键盘打开而不滚动webview时。

在此输入图像描述 在此输入图像描述 My webview code: 我的webview代码:

    WebView webview = (WebView) findViewById(R.id.webview);
    webview.getSettings().setJavaScriptEnabled(true);
    webview.getSettings().setAllowFileAccess(true);
    webview.setVerticalScrollBarEnabled(true);
    webview.setDownloadListener(this);
    webview.requestFocus(View.FOCUS_DOWN);
    webview.requestFocus(View.FOCUS_UP);
    webview.loadUrl("WEBVIEW URL");

Webview layout: Webview布局:

            <android.support.design.widget.AppBarLayout
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:theme="@style/AppTheme.AppBarOverlay">

    <android.support.v7.widget.Toolbar
        android:id="@+id/toolbar"
        android:layout_width="match_parent"
        android:layout_height="?attr/actionBarSize"
        android:background="?attr/colorPrimary"
        app:popupTheme="@style/AppTheme.PopupOverlay" />

</android.support.design.widget.AppBarLayout>

<include layout="@layout/content_main" />

<RelativeLayout
    android:id="@id/activity_main"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:background="#FFFFFF">

    <RelativeLayout
        android:id="@id/header"
        android:layout_width="fill_parent"
        android:layout_height="260.0dip"
        android:layout_alignParentLeft="true"
        android:layout_alignParentStart="true"
        android:layout_alignParentTop="true"
        android:background="@drawable/header" />

    <RelativeLayout
        android:id="@id/logo_main"
        android:layout_width="170.0dip"
        android:layout_height="170.0dip"
        android:layout_above="@+id/container"
        android:layout_centerHorizontal="true"
        android:layout_marginBottom="28dp"
        android:background="@drawable/logo" />

    <RelativeLayout
        android:id="@id/container"
        android:layout_width="fill_parent"
        android:layout_height="fill_parent"
        android:layout_below="@id/header">

        <WebView
            android:id="@+id/webview"
            android:layout_width="match_parent"
            android:layout_height="100.0dp"
            android:layout_below="@+id/insert_link"
            android:layout_alignParentLeft="true"
            android:layout_alignParentStart="true"
            android:layout_alignParentBottom="true"
            android:layout_centerHorizontal="true"
            android:layout_above="@+id/adView" />

        <com.google.android.gms.ads.AdView
            android:id="@+id/adView"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_alignParentBottom="true"
            android:layout_centerHorizontal="true"
            app:adSize="SMART_BANNER"
            app:adUnitId="@string/admob_banner_id" />

        <TextView
            android:id="@+id/downloader"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_alignParentTop="true"
            android:layout_centerHorizontal="true"
            android:layout_marginTop="18dp"
            android:textSize="27dp" />

        <TextView
            android:id="@+id/insert_link"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="@string/insert_link"
            android:textSize="17dp"
            android:layout_below="@+id/downloader"
            android:layout_centerHorizontal="true" />
    </RelativeLayout>

</RelativeLayout>

I tired this solutions but still same: WebView doesn't scroll when keyboard opened 我厌倦了这个解决方案,但仍然相同: 当键盘打开时,WebView不会滚动

WebView textarea doesn't pop up the keyboard WebView textarea不会弹出键盘

What can I do about it? 我能做些什么呢?

You have to resize your layout when keyboard open, so it would be scrollable in other area keyboard打开时你必须调整你的布局大小,所以它可以在其他区域滚动

set programmatically 以编程方式设置

getWindow().setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_ADJUST_RESIZE);

and change height of WebView 并更改WebView的高度

android:layout_height="100.0dp" 机器人:layout_height = “100.0dp”

to

android:layout_height="match_parent" 机器人:layout_height = “match_parent”

android:windowSoftInputMode="stateVisible|adjustResize" 

在活动清单文件中添加此行

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM