Disable EditText blinking cursor

前端 未结 10 1965
耶瑟儿~
耶瑟儿~ 2020-11-28 02:27

Does anyone know how to disable the blinking cursor in an EditText view?

相关标签:
10条回答
  • 2020-11-28 03:14

    You can use either the xml attribute android:cursorVisible="false" or the java function setCursorVisible(false).

    0 讨论(0)
  • 2020-11-28 03:15
    1. Change focus to another view (ex: Any textview or Linearlayout in the XML) using

      android:focusableInTouchMode="true"
      android:focusable="true"
      
    2. set addTextChangedListener to edittext in Activity.

    3. and then on aftertextchanged of Edittext put edittext.clearFocus();

    This will enable the cursor when keyboard is open and disable when keyboard is closed.

    0 讨论(0)
  • 2020-11-28 03:19

    You can use following code for enabling and disabling edit text cursor by programmatically.

    To Enable cursor

        editText.requestFocus();
        editText.setCursorVisible(true);
    

    To Disable cursor

        editText.setCursorVisible(false);
    

    Using XML enable disable cursor

       android:cursorVisible="false/true"
       android:focusable="false/true"
    

    To make edit_text Selectable to (copy/cut/paste/select/select all)

       editText.setTextIsSelectable(true);
    

    To focus on touch mode write following lines in XML

      android:focusableInTouchMode="true"
      android:clickable="true"
      android:focusable="true" 
    

    programmatically

      editText.requestFocusFromTouch();
    

    To clear focus on touch mode

      editText.clearFocus()
    
    0 讨论(0)
  • 2020-11-28 03:19

    If you want to ignore the Edittext from the starting of activity, android:focusable and android:focusableInTouchMode will help you inshallah.

    <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">
    

    This LinearLayout with your Edittext.

    0 讨论(0)
提交回复
热议问题