键盘隐藏WebView

时间:2015-10-13 21:45:07

标签: android webview android-softkeyboard

我有一个布局:

<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"
          tools:context=".StreamActivity"
          android:orientation="vertical">

<FrameLayout
    android:id="@+id/streamLayout"
    android:layout_width="fill_parent"
    android:layout_height="wrap_content">

    <SurfaceView
        android:id="@+id/surface"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_gravity="start">
    </SurfaceView>

</FrameLayout>

<WebView
    android:id="@+id/web_view"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:layout_gravity="start"/>

视频播放器的FrameLayout。 WebView是一个聊天。 当我开始在聊天中键入文本时,键盘会隐藏输入字段。

我尝试使用android:windowSoftInputMode,但它对我不起作用。聊天问题,它是在Angular上编写的,调整WebView的大小不会改变聊天的大小,必须像webView.loadUrl一样手动完成(&#34; javascript:$(&#39; section.content-window:第一个&#39;)。css(&#39; height&#39;,&#39;&#34; + finalSize +&#34; px&#39;);&#34;);

我有一个在显示和隐藏键盘时触发的监听器。 我想在显示键盘时手动更改聊天的大小,但是效果不好,因为当我改变聊天的大小时,它会失去焦点并且键盘会隐藏。

我还想过将Activity的内容放在ScrollView中。如果覆盖OnTouchListener,这将按用户锁定滚动,但我仍然可以从代码滚动。所以,我想如果键盘显示然后滚动活动的内容,那么它将在整个聊天中可见。我认为这会有效,但不好,因为它会锁定WebView中的滚动。

建议如何使用键盘和聊天解决此问题?

1 个答案:

答案 0 :(得分:0)

我找到了解决方案:

return Q.Promise<void>((resolve,reject) => {
    resolve(null);
}

并且喜欢这个

<ScrollView ...
        <LinearLayout ...
            ...
            <com.package.TouchyWebView
                android:layout_width="match_parent"
                android:layout_height="match_parent"
                android:id="@+id/webView"/>
            ...
        </LinearLayout>
</ScrollView>

package com.mypackage.common.custom.android.widgets

public class TouchyWebView extends WebView {

    public TouchyWebView(Context context) {
        super(context);
    }

    public TouchyWebView(Context context, AttributeSet attrs) {
        super(context, attrs);
    }

    public TouchyWebView(Context context, AttributeSet attrs, int defStyle) {
        super(context, attrs, defStyle);
    }

    @Override
    public boolean onTouchEvent(MotionEvent event){
        requestDisallowInterceptTouchEvent(true);
        return super.onTouchEvent(event);
    }          
}

滚动我使用这样的代码

scrollView.setOnTouchListener(new View.OnTouchListener() {
            @Override
            public boolean onTouch(View v, MotionEvent event) {
                    return true;
            }
        });
相关问题