【问题标题】:Android WebView input type="text" cursor not showingAndroid WebView输入类型=“文本”光标不显示
【发布时间】:2019-04-22 15:57:06
【问题描述】:

当我在 WebView 中单击输入文本字段 (input type="text") 时,该字段显示软键盘但未显示光标。 我可以输入文字,但没有光标... 发生这种情况时,Logcat 会说 "W/IInputConnectionWrapper﹕ showStatusIcon on inactive InputConnection" or "W/IInputConnectionWrapper﹕ getTextBeforeCursor on inactive InputConnection". 我试图 override 我的 WebView 制作 onCheckIsTextEditor() return true;,但没有任何效果。 请帮忙。

【问题讨论】:

    标签: android webview


    【解决方案1】:

    我通过将焦点设置为 WebView 的封闭视图解决了这个问题。

    <?xml version="1.0" encoding="utf-8"?>
    <FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:focusable="true"
        android:focusableInTouchMode="true">
        <WebView
            android:id="@+id/web_view"
            android:layout_width="match_parent"
            android:layout_height="match_parent"/>
        <include
            android:id="@+id/progress_bar"
            layout="@layout/progress_bar"/>
    </FrameLayout>
    

    【讨论】:

    • 仅作记录 - 它帮助我解决了用于 Instagram 登录过程的三星 Galaxy S3 WebView 问题。
    • 找了很久,谢谢。但是focusable 对我来说已经足够了,实际上删除focusableInTouchMode 使触摸选择更加顺畅!
    【解决方案2】:

    这可能是由于光标颜色而发生的。您可以制作自己的自定义光标。

    在drawable文件夹color_cursor.xml中创建一个XML文件

    <?xml version="1.0" encoding="utf-8"?>
    <shape xmlns:android="http://schemas.android.com/apk/res/android" >
        <size android:width="2dp" />
        <solid android:color="@color/cp_red"  />
    </shape> 
    

    并使用此属性

    <item name="android:textCursorDrawable">@drawable/color_cursor</item>
    

    【讨论】:

    • 我不知道有办法改变光标颜色。但是,更改光标颜色对我不起作用。还是谢谢你的建议。
    猜你喜欢
    • 2015-03-24
    • 1970-01-01
    • 2014-02-24
    • 1970-01-01
    • 1970-01-01
    • 2014-10-24
    • 1970-01-01
    • 2011-12-16
    • 1970-01-01
    相关资源
    最近更新 更多