Android IDE (AIDE) Support Forum

Is it possible to implement a cursor caret?

Hi there, since I am making a note taking app. Lots of samples that I have went to. I observed that there is a cursor caret highlight in the current line. In the view of this, anyone knows how to implement it with EditText?
Thanks.

(the darken cyan rectangle is the cursor caret highlight as I said)

Sure, setting a background shape to the edittext would do the trick

Inside the drawable folder create an xml resource with the following shape

		<!--corners allow us to make the rounded corners button-->
		<corners android:radius="3dp" />
	</shape>
</item>

Then set it as a background for the edittext.
It would be preferable to set it programmatically on focus change listener so it can be highlighted and remove the background when it loses focus.

thx for your advanced. However, I prefer to implement the highlight caret in the current line rather than highlighting all of the line that are created.
Just follow the position of the cursor to highlight whole line.

Idk if there’s any mistakes?

it now performs like this.

thx

Try to set a default background when it has no focus , but instead of the else statement write if(has focus==false) , try to figure out but yourself which is the default background for edittext

thx for yr help. I implemented it with onDraw, anyways thx for your assist.

1 Like