Quick Tip: Android — Hiding Edit Text Cursor on Activity Start
In this quick tip, I’ll be showing you how to remove the automatic cursor on Edit Text’s in Android when an Activity / Fragment is launched.
This is useful when you want to remove the focus away from the Edit Texts when an application is launched.
In the caption above we can see that the Edit Text automatically focuses when the application is launched showing a cursor.
Set Cursor Visibility
There are two Edit Texts in the application:
To hide the cursor we implement this method for each Edit Text:
This method hides the cursor in the Edit Text when the application launches.
Now when the application launches, the automatic cursor does not appear. The user can still change the Edit Text but there isn’t a cursor available to track where the user is typing. We can reintroduce the cursor when the user clicks on the Edit Text.
Reintroduce the Cursor
To reintroduce the cursor, we set an onClickListener on the Edit Text. When the user clicks on the Edit Text, cursor visibility is set to true.
The cursor reappears when the user clicks on the Edit Text and can update the text.
Thanks for reading! Please recommend this post (by clicking the ❤ ) so other people can find it.
Meanwhile, would love to hear your suggestions & comments on this article.
Christopher Coverdale is a Android Developer at Cotham Technologies, building the next generation no-code platform for mobile development. An entrepreneur and tech nut, tinkering away with IOT and Machine Learning projects.