Home » Java » java – I want a way to hide the cursor from EditText-Exceptionshub

java – I want a way to hide the cursor from EditText-Exceptionshub

Posted by: admin February 25, 2020 Leave a comment

Questions:

How to make the cursor automatically disappear from EditText when not writing ?

I want something easy to understand. I am not a much programming expert

<android.support.design.widget.TextInputEditText
                                android:id="@+id/name1"
                                android:layout_width="match_parent"
                                android:layout_height="wrap_content"
                                android:layout_marginTop="8dp"
                                android:ems="8"
                                android:fontFamily="@font/bahij_janna"
                                android:hint="@string/team_2"
                                android:lines="1"
                                android:textColor="?attr/textColor"
                                android:inputType="textCapWords"
                                />

enter image description here

See an example of the problem via the link

How to&Answers:

android:textCursorDrawable=”@null”

you can set the cursor as null for hide the cursor till the click event occured.
the cursor will shows up when you click the edittext to start typing.

cursor will always help us to copy and paste the text.

Answer:

To remove the cursor from edittext you need to set

text.setFocusable(false);

text.setOnTouchListener(new View.OnTouchListener() {

        @Override
        public boolean onTouch(View v, MotionEvent event) {

            text.setFocusableInTouchMode(true);
            return false;
        }

});