代码之家  ›  专栏  ›  技术社区  ›  epanalepsis

Android WebView-活动启动后忽略第一次单击/触摸

  •  0
  • epanalepsis  · 技术社区  · 6 年前

    我试着描述一下发生了什么。我们调用webview,生成带有视图特定模型的razor html模板。之后,我们使用“LoadDataWithBaseUrl”调用视图。视图由webview控件加载。现在我将尝试使用在视图中实现的按钮。按钮的onclick处理程序在javascript的views header部分script标记中实现。实施示例:

    ...
    function ClearInput() {
        var input = document.getElementById('page-text-input');
        input.value = "";
    }
    ...
    <input type="button" class="numeric-input-function" onclick="ClearInput();"/>
    

    出现的问题是,在webview控件呈现视图之后,我们无法直接使用按钮。看起来javascript不是直接可用的。进程中的第一个按钮单击没有引发单击事件。第二次点击和随后的一个工作。

    由于这种错误行为,我们限制了可用性。 要澄清:用户看到视图,但无法正常操作,因为无法识别第一次单击的单击事件。

    还有谁有同样的问题或解决方案吗?

    编辑: 似乎webview没有集中在start上,需要第一次单击来设置焦点。

    编辑2: 我做了更多的测试,并认识到输入通道在每次调用webview时都会在其构造完成后立即被破坏。相应的调试输出如下所示:

    08-16 16:50:01.583 D/InputTransport(31313): Input channel constructed: fd=144
    08-16 16:50:01.583 D/InputTransport(31313): Input channel destroyed: fd=132
    08-16 16:50:03.813 D/Mono    (31313): GC_BRIDGE waiting for bridge processing to finish
    08-16 16:50:03.856 I/art     (31313): Starting a blocking GC Explicit
    08-16 16:50:03.894 I/art     (31313): Explicit concurrent mark sweep GC freed 18081(2MB) AllocSpace objects, 87(4MB) LOS objects, 14% free, 91MB/107MB, paused 559us total 38.349ms
    08-16 16:50:03.927 D/Mono    (31313): GC_TAR_BRIDGE bridges 6498 objects 8686 opaque 242 colors 6492 colors-bridged 6479 colors-visible 6479 xref 101 cache-hit 0 cache-semihit 0 cache-miss 13 setup 0.72ms tarjan 7.96ms scc-setup 2.09ms gather-xref 0.36ms xref-setup 0.07ms cleanup 0.76ms
    08-16 16:50:03.927 D/Mono    (31313): GC_BRIDGE: Complete, was running for 114.00ms
    08-16 16:50:03.927 D/Mono    (31313): GC_MAJOR: (LOS overflow) time 102.71ms, stw 104.75ms los size: 27552K in use: 23334K
    08-16 16:50:03.927 D/Mono    (31313): GC_MAJOR_SWEEP: major size: 10240K in use: 8427K
    08-16 16:50:07.126 D/ViewRootImpl@22ae52[CoordinatorActivity](31313): Relayout returned: oldFrame=[0,0][2048,1536] newFrame=[0,0][2048,1536] result=0x1 surface={isValid=true -913786880} surfaceGenerationChanged=false
    08-16 16:50:08.112 D/ViewRootImpl@22ae52[CoordinatorActivity](31313): ViewPostImeInputStage processPointer 0
    08-16 16:50:08.215 D/ViewRootImpl@22ae52[CoordinatorActivity](31313): ViewPostImeInputStage processPointer 1
    08-16 16:50:08.732 D/ViewRootImpl@22ae52[CoordinatorActivity](31313): ViewPostImeInputStage processPointer 0
    08-16 16:50:08.800 D/ViewRootImpl@22ae52[CoordinatorActivity](31313): ViewPostImeInputStage processPointer 1
    08-16 16:50:08.818 D/InputMethodManager(31313): HSI from window - flag : 0 Pid : 31313
    08-16 16:50:08.824 D/InputMethodManager(31313): HSI from window - flag : 0 Pid : 31313
    08-16 16:50:08.828 D/InputMethodManager(31313): HSI from window - flag : 0 Pid : 31313
    08-16 16:50:08.831 D/InputMethodManager(31313): HSI from window - flag : 0 Pid : 31313
    

    我尝试了不同的标志,focusable和focusableInTouchMode以及ontouch/onfocuschanged事件处理程序的设置,但似乎没有任何效果。没人知道怎么解决这个问题?

    1 回复  |  直到 6 年前
        1
  •  0
  •   epanalepsis    6 年前

    我找到了解决办法。原因是设置了“系统用户界面标志隐藏导航”。我不知道为什么会发生这种副作用,但我把线拔掉后,它就起作用了。以防其他人也遇到这个问题。