How to add pagelines to a EditText in android? -


is possible show pagelines in edittext?

i mean these lines:

enter image description here

let's edittext 500 500 pixels in size. want lines visible across 500 500 square.

is there build in way this? tried google couldn't find answer. guess other option dynamically create graphic based on textheight , linespacing, such ugly work-around.

the notepad application sample android dev site shows how this.

http://developer.android.com/resources/samples/notepad/index.html

looks (scroll down code):

notepad

most of relevant code in this file. pay attention linededittext inner class. defined within activity. draws lines required.

inside activity oncreate() method, setcontentview(r.id.note_editor) set view, defined here

snippet extracted here. update: code modified @pieter888 draw lines on entire edittext control.

import android.content.context; import android.graphics.canvas; import android.graphics.paint; import android.graphics.rect; import android.util.attributeset; import android.widget.edittext;  public class linededittext extends edittext  {     private rect mrect;     private paint mpaint;      public linededittext(context context, attributeset attrs)      {         super(context, attrs);         mrect = new rect();         mpaint = new paint();         mpaint.setstyle(paint.style.stroke);         mpaint.setcolor(0xff000000);     }      /**      * called draw linededittext object      * @param canvas canvas on background drawn.      */     @override     protected void ondraw(canvas canvas)      {         int height = canvas.getheight();         int curheight = 0;         rect r = mrect;         paint paint = mpaint;         int baseline = getlinebounds(0, r);         (curheight = baseline + 1; curheight < height;                                                   curheight += getlineheight())         {             canvas.drawline(r.left, curheight, r.right, curheight, paint);         }         super.ondraw(canvas);     } } 

Comments

Popular posts from this blog

django - How can I change user group without delete record -

java - Need to add SOAP security token -

java - EclipseLink JPA Object is not a known entity type -