键盘没有显示在简单的自定义WebView上(没有代码更改),为什么?

时间:2017-08-16 08:34:03

标签: android webview android-custom-view

我有一个简单的WebView,如下所示

<WebView
    android:id="@+id/my_web_view"
    android:layout_width="match_parent"
    android:layout_height="match_parent" />

以上效果很好,当我点击编辑文本(webview上的输入元素)时,会出现键盘。

我正在考虑自定义我的WebView。所以我写了一个类,从WebView继承如下(现在是空体,所以一切都按照WebView)。

class MyWebView @JvmOverloads constructor(
    context: Context, attrs: AttributeSet? = null, defStyleAttr: Int = 0
) : WebView(context, attrs, defStyleAttr) { }

因此,要使用我的自定义WebView,我的视图已更改为

<my.package.MyWebView
    android:id="@+id/my_web_view"
    android:layout_width="match_parent"
    android:layout_height="match_parent" />

所有编译都正常,并且webview已加载。但是,当单击编辑文本(webview上的输入元素)时,键盘将不再可见。

会发生什么?我怎么能用自定义WebView看到相同的键盘行为?

1 个答案:

答案 0 :(得分:0)

我得到了显示键盘的解决方法

<my.package.MyWebView
    android:id="@+id/my_web_view"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:focusable="true"
    android:focusableInTouchMode="true" />

但我仍然不明白为什么在普通的WebView上,不需要android:focusable="true"android:focusableInTouchMode="true"。希望有人解释。

相关问题