I wanted to display blinking cursor at the end of the text in TextView .
I tried by android:cursorVisible=\"true\"
in TextView But no go .
Even i t
There is a solution for this.
I had to do this when I was making a terminal app and I used a simple runnable
put a cursor at the end and make it blink.
I made 3 class variables:
private boolean displayCursor;
private boolean cursorOn;
private String terminalText;
private TextView terminal; // The TextView Object
terminalText
keeps track of the text to be displayed.
Created a class method that runs the runnable
the first time
private void runCursorThread() {
Runnable runnable = new Runnable() {
public void run() {
if (displayCursor) {
if (cursorOn) {
terminal.setText(terminalText);
} else {
terminal.setText(terminalText + '_');
}
cursorOn = !cursorOn;
}
terminal.postDelayed(this, 400);
}
};
runnable.run();
}
And initiated the variables and called runCursorThread()
in onCreate()
cursorOn = false;
displayCursor = true;
runCursorThread();