【问题标题】:Android Webview - how to only allow input from hardware keyboard?Android Webview - 如何只允许从硬件键盘输入?
【发布时间】:2019-10-19 08:35:30
【问题描述】:

我有一个基本上只是一个 WebView 的应用程序。我想接受来自硬件键盘的输入。我还没有想出一种方法来隐藏/禁用 Android 软键盘而不禁用硬键盘。

这段代码奇怪地允许文本字段被聚焦并且光标显示在字段中,但是我不能输入任何字符:

<WebView
   android:id="@+id/webview"
   android:focusable="false"
   android:focusableInTouchMode="false"
   android:layout_width="match_parent"
   android:layout_height="match_parent"/>

我尝试了很多东西,但似乎没有任何效果。我觉得这是不可能的,但听起来应该是这样。

提前致谢

【问题讨论】:

    标签: java android webview android-webview


    【解决方案1】:

    请在此处查看 Android 团队的回答:

    Disable SoftKeyboard inside a WebView

    在您的 layout.xml 中的主(父)布局中添加以下代码

    android:descendantFocusability="blocksDescendants"
    

    并在您的 webview 中设置以下属性

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

    如果这也阻止了您的硬件键盘,那么这个其他方法应该适合您:

    How to hide keyboard when user clicks on textbox in webview android

    【讨论】:

    • 之前尝试过第一个解决方案。不起作用,它会禁用输入框,因此它们根本无法聚焦。我在发布的链接中尝试了一些解决方案,但没有成功,但我会运行更多,看看我是否可以让它与其中一个一起工作并报告。谢谢
    • @AaronMcKellar 这种检测软件键盘何时打开然后隐藏它的解决方案怎么样? stackoverflow.com/a/33657024/4318658
    猜你喜欢
    • 1970-01-01
    • 2019-06-17
    • 2013-12-06
    • 2012-06-12
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2013-09-28
    相关资源
    最近更新 更多