有人知道如何禁用EditText视图中的闪烁光标吗?


当前回答

如果你想忽略Edittext从开始的活动,android:focusable和android:focusableInTouchMode将帮助你。

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:id="@+id/linearLayout7" android:layout_width="fill_parent"
    android:layout_height="wrap_content"
    android:focusable="true" android:focusableInTouchMode="true">

这个LinearLayout和你的Edittext。

其他回答

将游标可见性设置为true和false的问题可能是一个问题,因为它会删除游标,直到您再次设置它,同时字段是可编辑的,这不是很好的用户体验。

所以不用

setCursorVisible(false)

就像这样做

        editText2.setFocusableInTouchMode(false)
        editText2.clearFocus()
        editText2.setFocusableInTouchMode(true)

上面的代码删除焦点,进而删除游标。并再次启用它,这样你就可以再次触摸它并编辑它。就像普通的用户体验一样。

改变焦点到另一个视图(例如:任何textview或XML中的线性布局)使用 android: focusableInTouchMode = " true " android: focusable = " true " 在Activity中设置addTextChangedListener为edittext。 然后在aftertextchanged of Edittext上放置Edittext . clearfocus ();

这将在键盘打开时启用光标,在键盘关闭时禁用光标。

在kotlin中your_edittext。isCursorVisible = false

rootLayout.findFocus .clearFocus (());

你可以使用xml属性android:cursorVisible="false"或通过编程方式:

java: view.setCursorVisible(假) 芬兰湾的科特林:视图。isCursorVisible = false