【问题标题】:Android keyboard not showing when clicking on input in webview在webview中单击输入时不显示Android键盘
【发布时间】:2016-01-05 23:20:39
【问题描述】:

我在我的 android 应用程序中实现了一个自定义 webview。如果我触摸此 web 视图中的输入或文本区域,则不会显示软键盘。我没有覆盖我的 web 视图中的任何触摸监听器,也没有更改清单中的任何内容。谁能帮我弄清楚为什么键盘不显示?

我的布局代码:

<RelativeLayout 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=".MainActivity">

    <android.support.v4.widget.SwipeRefreshLayout
        android:id="@+id/swipeRefreshLayout"
        android:layout_width="match_parent"
        android:layout_height="match_parent">

        <nl.AEGEE.enschede.android.AEGEEWebView
            android:id="@+id/webView"
            android:layout_width="match_parent"
            android:layout_height="match_parent" />

    </android.support.v4.widget.SwipeRefreshLayout>

    <ProgressBar
        android:id="@+id/progressBar"
        style="?android:attr/progressBarStyleHorizontal"
        android:progressTint="@color/aegee_blue"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_marginTop="-6dp"
        android:layout_alignParentTop="true" />

</RelativeLayout>

【问题讨论】:

    标签: android webview android-softkeyboard


    【解决方案1】:

    请尝试将这些行添加到 XML 文件中的 webview。

    android:focusable="true"
    android:focusableInTouchMode="true"
    

    希望对你有帮助。

    【讨论】:

    • 非常感谢,仅此而已!奇怪的是,我在代码中扩展了一个 WebView,而没有 customwebview,一切都按预期工作。
    • 不适用于网络视图中的 Google 表单
    • @KonstantinKonopko 你是怎么解决的?
    【解决方案2】:

    就我而言,除了添加

    android:focusable="true"
    android:focusableInTouchMode="true"
    

    我还需要继承 WebView 并添加此方法

    @Override
    public boolean onCheckIsTextEditor() {
        return true;
    }
    

    我从this thread 那里得到了解决方案,那里提出了许多其他解决方案。

    这是整个 WebView 子类,如果有人想使用它

    public class CustomWebView extends WebView {
        public CustomWebView(Context context) {
            super(context);
    
            init();
        }
    
        public CustomWebView(Context context, AttributeSet attrs) {
            super(context, attrs);
    
            init();
        }
    
        public CustomWebView(Context context, AttributeSet attrs, int defStyleAttr) {
            super(context, attrs, defStyleAttr);
    
            init();
        }
    
        protected void init() {
            setFocusable(true);
            setFocusableInTouchMode(true);
        }
    
        @Override
        public InputConnection onCreateInputConnection(EditorInfo outAttrs) {
            BaseInputConnection baseInputConnection = new BaseInputConnection(this, false);
            outAttrs.imeOptions = IME_ACTION_DONE;
            outAttrs.inputType = TYPE_CLASS_TEXT;
            return baseInputConnection;
        }
    
        @Override
        public boolean onCheckIsTextEditor() {
            return true;
        }
    }
    

    【讨论】:

    【解决方案3】:
    setFocusable(true)
    setFocusableInTouchMode(true)
    

    【讨论】:

    • 请对您的回答提供某种解释,否则将被标记为低质量。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2013-09-14
    • 1970-01-01
    • 2011-05-11
    • 1970-01-01
    • 2017-05-02
    • 2022-09-23
    相关资源
    最近更新 更多