Is it possible to show pagelines in a EditText
?
I mean these lines:
Let's say my EditText
is 500 by 500 pixels in size. I want those lines to be visible across that 500 by 500 square.
Is there a build in way to do this? I already tried Google but I couldn't find an answer. I guess my other option is to dynamically create a graphic based on the textheight and linespacing, such an ugly work-around.
The notepad application sample from the android dev site shows you how to do this.
http://developer.android.com/resources/samples/NotePad/index.html
Looks like this (scroll down for code):
Most of the relevant code is in this file. Pay attention to the
LinedEditText
inner class. It is defined within the activity. It draws the lines required.Inside the activity
onCreate()
method,setContentView(R.id.note_editor)
is set as the view, it is defined like hereSnippet extracted from here. Update: Code modified by @Pieter888 to draw lines on the entire
EditText
control.@gideon's answer above works well but has an issue when you enter more text in the
edittext
because more lines are not drawn accordingly. To solve this, I wrote an override foronMeasure()
and calledinvalidate()
. and more lines will be drawn when text increases.The code now is: