Pastebin launched a little side project called HostCabi.net, check it out ;-)Don't like ads? PRO users don't see any ads ;-)
Guest

Untitled

By: a guest on Jul 13th, 2013  |  syntax: None  |  size: 1.49 KB  |  hits: 25  |  expires: Never
download  |  raw  |  embed  |  report abuse  |  print
Text below is selected. Please press Ctrl+C to copy to your clipboard. (⌘+C on Mac)
  1. public class NotePade extends Activity {
  2. /** Called when the activity is first created. */
  3. @Override
  4. public void onCreate(Bundle savedInstanceState) {
  5.     super.onCreate(savedInstanceState);
  6.     setContentView(R.layout.main);
  7. }
  8.  
  9. public class LinedEditText extends EditText {
  10.     private Rect mRect;
  11.     private Paint mPaint;
  12.     // we need this constructor for LayoutInflater
  13.     public LinedEditText(Context context, AttributeSet attrs) {
  14.         super(context, attrs);
  15.         mRect = new Rect();
  16.         mPaint = new Paint();
  17.         mPaint.setStyle(Paint.Style.FILL_AND_STROKE);
  18.         // mPaint.setColor(R.color.edit_note_line); //SET YOUR OWN COLOR
  19.         // HERE
  20.         mPaint.setColor(Color.RED); // SET YOUR OWN COLOR HERE
  21.     }
  22.  
  23.     @Override
  24.     protected void onDraw(Canvas canvas) {
  25.         // int count = getLineCount();
  26.         int height = getHeight();
  27.         // int height = 100;
  28.         int line_height = getLineHeight();
  29.         int count = height / line_height;
  30.         if (getLineCount() > count)
  31.             count = getLineCount();// for long text with scrolling
  32.  
  33.         Rect r = mRect;
  34.         Paint paint = mPaint;
  35.         int baseline = getLineBounds(0, r);// first line
  36.         for (int i = 0; i < count; i++) {
  37.             canvas.drawLine(r.left, baseline + 1, r.right, baseline + 1,
  38.                     paint);
  39.             baseline += getLineHeight();// next line
  40.         }
  41.         super.onDraw(canvas);
  42.     }
  43. }
  44.        
  45. <com.dinash.notepad.LinedEditText></com.dinash.notepad.LinedEditText>